From 50188f1851a14b173550ab0b5182b505c96d5005 Mon Sep 17 00:00:00 2001 From: afornerot Date: Tue, 29 Aug 2023 13:05:31 +0200 Subject: [PATCH] correction synchro breakday --- .../src/Command/BreakdayCommand.php | 47 ++++++++++++++++++- 1 file changed, 45 insertions(+), 2 deletions(-) diff --git a/src/ninebadge-1.0/src/Command/BreakdayCommand.php b/src/ninebadge-1.0/src/Command/BreakdayCommand.php index 12c4563..f2a671b 100644 --- a/src/ninebadge-1.0/src/Command/BreakdayCommand.php +++ b/src/ninebadge-1.0/src/Command/BreakdayCommand.php @@ -91,12 +91,28 @@ class BreakdayCommand extends Command $end->modify("last day of this month"); $end->modify("next sunday"); + // On récupère la première journée de pointage de l'utilisateur + $qb = $this->em->createQueryBuilder() + ->select('tallyday') + ->from('App:Tallyday','tallyday') + ->Where('tallyday.user=:user') + ->setParameter('user',$user) + ->orderBy('tallyday.dateof', 'ASC') + ->setMaxResults(1); + + $datas = $qb->getQuery()->getResult(); + if(empty($datas)) continue; + $firstday=$datas[0]->getDateof(); + $this->writeln("FIRST DAY = ".$firstday->format("d/m/Y")); + $response=$this->api("POST",$url."/getBreakdays",json_encode(["key"=>$key,"username"=>$user->getUsername()])); - if($response&&$response->code=="200") { while($start<=$end) { $havebreakday=false; - if($start->format("w")!=0&&$start->format("w")!=6) { + $havebreakdayAM=false; + $havebreakdayPM=false; + + if($start->format("w")!=0&&$start->format("w")!=6&&$start>=$firstday) { foreach($response->body->events as $event) { if($event->eventallday) { $manip=clone $start; @@ -208,6 +224,7 @@ class BreakdayCommand extends Command } $havebreakday=true; + $havebreakdayAM=true; } } else { @@ -259,6 +276,7 @@ class BreakdayCommand extends Command } $havebreakday=true; + $havebreakdayPM=true; } } } @@ -274,6 +292,31 @@ class BreakdayCommand extends Command $this->em->flush(); } } + else { + // Si congés matin mais par l'après midi on supprime un congés potentiel de l'aprés midi + if($havebreakdayAM && !$havebreakdayPM) { + $manip=clone $start; + $manip->setTime(13,30); + $tallydays=$this->em->getRepository("App:Tallyday")->findBy(["user"=>$user,"dateof"=>$start,"datestart"=>$manip,"validatemaster"=>false,"isbreakday"=>true]); + foreach($tallydays as $tallyday) { + $this->em->remove($tallyday); + $this->em->flush(); + } + } + + // Si congés aprèsmidi mais pas le matin on supprime un congés potentiel du matin + if(!$havebreakdayAM && $havebreakdayPM) { + $manip=clone $start; + $manip->setTime(8,30); + $tallydays=$this->em->getRepository("App:Tallyday")->findBy(["user"=>$user,"dateof"=>$start,"datestart"=>$manip,"validatemaster"=>false,"isbreakday"=>true]); + foreach($tallydays as $tallyday) { + + $this->em->remove($tallyday); + $this->em->flush(); + } + } + + } $start->add(new \DateInterval('P1D')); }