From 4ec5dceb147314d565923309a35c908955a56616 Mon Sep 17 00:00:00 2001 From: afornerot Date: Mon, 16 May 2022 14:53:47 +0200 Subject: [PATCH] ne pas importer de breakday les weekend (fixes #7) --- .../src/Command/BreakdayCommand.php | 242 +++++++++--------- 1 file changed, 122 insertions(+), 120 deletions(-) diff --git a/src/ninebadge-1.0/src/Command/BreakdayCommand.php b/src/ninebadge-1.0/src/Command/BreakdayCommand.php index 5f830e2..80db90b 100644 --- a/src/ninebadge-1.0/src/Command/BreakdayCommand.php +++ b/src/ninebadge-1.0/src/Command/BreakdayCommand.php @@ -97,140 +97,45 @@ class BreakdayCommand extends Command if($response&&$response->code=="200") { while($start<=$end) { $havebreakday=false; - foreach($response->body->events as $event) { - if($event->eventallday) { - $manip=clone $start; - $manip->setTime(8,0); - if(new \Datetime($event->eventstart)<=$manip && $manip < new \Datetime($event->eventend) ) { - $this->writeln($start->format("d/m/Y")." >> tallybreakday full day"); - - // On s'assure que la journée n'a pas été validé master - $tallyday=$this->em->getRepository("App:Tallyday")->findOneBy(["user"=>$user,"dateof"=>$start,"validatemaster"=>true]); - if(!$tallyday) { - // Les pointages de la journée qui ne sont des congès sont supprimés - $tallydays=$this->em->getRepository("App:Tallyday")->findBy(["user"=>$user,"dateof"=>$start,"isbreakday"=>false]); - foreach($tallydays as $tallyday) { - $this->em->remove($tallyday); - $this->em->flush(); - } - - // Les breakday am sont supprimés - $manip=clone $start; - $manip->setTime(8,30); - $tallydays=$this->em->getRepository("App:Tallyday")->findBy(["user"=>$user,"dateof"=>$start,"datestart"=>$manip,"isbreakday"=>true]); - foreach($tallydays as $tallyday) { - $this->em->remove($tallyday); - $this->em->flush(); - } - - // Les breakday pm sont supprimés - $manip=clone $start; - $manip->setTime(13,30); - $tallydays=$this->em->getRepository("App:Tallyday")->findBy(["user"=>$user,"dateof"=>$start,"datestart"=>$manip,"isbreakday"=>true]); - foreach($tallydays as $tallyday) { - $this->em->remove($tallyday); - $this->em->flush(); - } - - // Le breakday est généré s'il n'existe pas - $manip=clone $start; - $manip->setTime(10,00); - $tallyday=$this->em->getRepository("App:Tallyday")->findOneBy(["user"=>$user,"dateof"=>$start,"datestart"=>$manip,"isbreakday"=>true]); - if(!$tallyday) { - $data = new Tallyday(); - $data->setDateof($start); - $data->setUser($user); - $data->setValidateuser(false); - $data->setValidatemaster(false); - $data->setIsbreakday(true); - $data->setName($event->taskname); - $data->setDatestart(clone $manip); - - $manip->add(new \DateInterval("PT7H")); - $data->setDateend(clone $manip); - $this->em->persist($data); - $this->em->flush(); - } - - $havebreakday=true; - } - } - } - else { - $manip=clone $start; - $manip->setTime(10,0); - if(new \Datetime($event->eventstart)<=$manip && $manip < new \Datetime($event->eventend) ) { - $this->writeln($start->format("d/m/Y")." >> tallybreakday AM"); - // On s'assure que la journée n'a pas été validé master - $tallyday=$this->em->getRepository("App:Tallyday")->findOneBy(["user"=>$user,"dateof"=>$start,"validatemaster"=>true]); - if(!$tallyday) { - // Les pointages du matin qui ne sont des congès sont supprimés - $tallydays=$this->em->getRepository("App:Tallyday")->findAM($user,$start,false); - foreach($tallydays as $tallyday) { - $this->em->remove($tallyday); - $this->em->flush(); - } - - // Les breakday fullday sont supprimés - $manip=clone $start; - $manip->setTime(10,0); - $tallydays=$this->em->getRepository("App:Tallyday")->findBy(["user"=>$user,"dateof"=>$start,"datestart"=>$manip,"isbreakday"=>true]); - foreach($tallydays as $tallyday) { - $this->em->remove($tallyday); - $this->em->flush(); - } - - // Le breakday est généré s'il n'existe pas - $manip=clone $start; - $manip->setTime(8,30); - $tallyday=$this->em->getRepository("App:Tallyday")->findOneBy(["user"=>$user,"dateof"=>$start,"datestart"=>$manip,"isbreakday"=>true]); - if(!$tallyday) { - $data = new Tallyday(); - $data->setDateof($start); - $data->setUser($user); - $data->setValidateuser(false); - $data->setValidatemaster(false); - $data->setIsbreakday(true); - $data->setName("AM = ".$event->taskname); - $data->setDatestart(clone $manip); - - $manip->add(new \DateInterval("PT3H")); - $manip->add(new \DateInterval("PT30M")); - $data->setDateend(clone $manip); - $this->em->persist($data); - $this->em->flush(); - } - - $havebreakday=true; - } - } - else { + if($start->format("w")!=0&&$start->format("w")!=6) { + foreach($response->body->events as $event) { + if($event->eventallday) { $manip=clone $start; - $manip->setTime(15,0); + $manip->setTime(8,0); if(new \Datetime($event->eventstart)<=$manip && $manip < new \Datetime($event->eventend) ) { - $this->writeln($start->format("d/m/Y")." >> tallybreakday PM"); + $this->writeln($start->format("d/m/Y")." >> tallybreakday full day"); + // On s'assure que la journée n'a pas été validé master $tallyday=$this->em->getRepository("App:Tallyday")->findOneBy(["user"=>$user,"dateof"=>$start,"validatemaster"=>true]); if(!$tallyday) { - // Les pointages de l'aprés midi qui ne sont des congès sont supprimés - $tallydays=$this->em->getRepository("App:Tallyday")->findPM($user,$start,false); + // Les pointages de la journée qui ne sont des congès sont supprimés + $tallydays=$this->em->getRepository("App:Tallyday")->findBy(["user"=>$user,"dateof"=>$start,"isbreakday"=>false]); foreach($tallydays as $tallyday) { $this->em->remove($tallyday); $this->em->flush(); } - - // Les breakday fullday sont supprimés + + // Les breakday am sont supprimés $manip=clone $start; - $manip->setTime(10,0); + $manip->setTime(8,30); $tallydays=$this->em->getRepository("App:Tallyday")->findBy(["user"=>$user,"dateof"=>$start,"datestart"=>$manip,"isbreakday"=>true]); foreach($tallydays as $tallyday) { $this->em->remove($tallyday); $this->em->flush(); } - - // Le breakday est généré s'il n'existe pas + + // Les breakday pm sont supprimés $manip=clone $start; $manip->setTime(13,30); + $tallydays=$this->em->getRepository("App:Tallyday")->findBy(["user"=>$user,"dateof"=>$start,"datestart"=>$manip,"isbreakday"=>true]); + foreach($tallydays as $tallyday) { + $this->em->remove($tallyday); + $this->em->flush(); + } + + // Le breakday est généré s'il n'existe pas + $manip=clone $start; + $manip->setTime(10,00); $tallyday=$this->em->getRepository("App:Tallyday")->findOneBy(["user"=>$user,"dateof"=>$start,"datestart"=>$manip,"isbreakday"=>true]); if(!$tallyday) { $data = new Tallyday(); @@ -239,7 +144,55 @@ class BreakdayCommand extends Command $data->setValidateuser(false); $data->setValidatemaster(false); $data->setIsbreakday(true); - $data->setName("PM = ".$event->taskname); + $data->setName($event->taskname); + $data->setDatestart(clone $manip); + + $manip->add(new \DateInterval("PT7H")); + $data->setDateend(clone $manip); + $this->em->persist($data); + $this->em->flush(); + } + + $havebreakday=true; + } + } + } + else { + $manip=clone $start; + $manip->setTime(10,0); + if(new \Datetime($event->eventstart)<=$manip && $manip < new \Datetime($event->eventend) ) { + $this->writeln($start->format("d/m/Y")." >> tallybreakday AM"); + // On s'assure que la journée n'a pas été validé master + $tallyday=$this->em->getRepository("App:Tallyday")->findOneBy(["user"=>$user,"dateof"=>$start,"validatemaster"=>true]); + if(!$tallyday) { + // Les pointages du matin qui ne sont des congès sont supprimés + $tallydays=$this->em->getRepository("App:Tallyday")->findAM($user,$start,false); + foreach($tallydays as $tallyday) { + $this->em->remove($tallyday); + $this->em->flush(); + } + + // Les breakday fullday sont supprimés + $manip=clone $start; + $manip->setTime(10,0); + $tallydays=$this->em->getRepository("App:Tallyday")->findBy(["user"=>$user,"dateof"=>$start,"datestart"=>$manip,"isbreakday"=>true]); + foreach($tallydays as $tallyday) { + $this->em->remove($tallyday); + $this->em->flush(); + } + + // Le breakday est généré s'il n'existe pas + $manip=clone $start; + $manip->setTime(8,30); + $tallyday=$this->em->getRepository("App:Tallyday")->findOneBy(["user"=>$user,"dateof"=>$start,"datestart"=>$manip,"isbreakday"=>true]); + if(!$tallyday) { + $data = new Tallyday(); + $data->setDateof($start); + $data->setUser($user); + $data->setValidateuser(false); + $data->setValidatemaster(false); + $data->setIsbreakday(true); + $data->setName("AM = ".$event->taskname); $data->setDatestart(clone $manip); $manip->add(new \DateInterval("PT3H")); @@ -248,10 +201,59 @@ class BreakdayCommand extends Command $this->em->persist($data); $this->em->flush(); } - + $havebreakday=true; } - } + } + else { + $manip=clone $start; + $manip->setTime(15,0); + if(new \Datetime($event->eventstart)<=$manip && $manip < new \Datetime($event->eventend) ) { + $this->writeln($start->format("d/m/Y")." >> tallybreakday PM"); + // On s'assure que la journée n'a pas été validé master + $tallyday=$this->em->getRepository("App:Tallyday")->findOneBy(["user"=>$user,"dateof"=>$start,"validatemaster"=>true]); + if(!$tallyday) { + // Les pointages de l'aprés midi qui ne sont des congès sont supprimés + $tallydays=$this->em->getRepository("App:Tallyday")->findPM($user,$start,false); + foreach($tallydays as $tallyday) { + $this->em->remove($tallyday); + $this->em->flush(); + } + + // Les breakday fullday sont supprimés + $manip=clone $start; + $manip->setTime(10,0); + $tallydays=$this->em->getRepository("App:Tallyday")->findBy(["user"=>$user,"dateof"=>$start,"datestart"=>$manip,"isbreakday"=>true]); + foreach($tallydays as $tallyday) { + $this->em->remove($tallyday); + $this->em->flush(); + } + + // Le breakday est généré s'il n'existe pas + $manip=clone $start; + $manip->setTime(13,30); + $tallyday=$this->em->getRepository("App:Tallyday")->findOneBy(["user"=>$user,"dateof"=>$start,"datestart"=>$manip,"isbreakday"=>true]); + if(!$tallyday) { + $data = new Tallyday(); + $data->setDateof($start); + $data->setUser($user); + $data->setValidateuser(false); + $data->setValidatemaster(false); + $data->setIsbreakday(true); + $data->setName("PM = ".$event->taskname); + $data->setDatestart(clone $manip); + + $manip->add(new \DateInterval("PT3H")); + $manip->add(new \DateInterval("PT30M")); + $data->setDateend(clone $manip); + $this->em->persist($data); + $this->em->flush(); + } + + $havebreakday=true; + } + } + } } } }