Commit 3327bf24 authored by Stephane Bouvry's avatar Stephane Bouvry
Browse files

Fix : Annulation des déclarations fonctionnelle

parent e7ad6f93
Loading
Loading
Loading
Loading
+24 −5
Changes for module/Oscar/src/Oscar/Service/TimesheetService.php: 24 added lines, 5 removed lines.
Original line number Diff line number Diff line
@@ -2115,25 +2115,44 @@ class TimesheetService implements ServiceLocatorAwareInterface, EntityManagerAwa
        return $query->getQuery()->getResult();
    }

    /**
     * Annulation des déclarations d'une personne pour la période (mois) données.
     *
     * @param Person $person
     * @param $period
     * @return bool
     * @throws \Doctrine\ORM\ORMException
     * @throws \Doctrine\ORM\OptimisticLockException
     */
    public function deleteValidationPeriodPerson(Person $person, $period)
    {
        $spli = explode('-', $period);
        $year = (int)$spli[0];
        $month = (int)$spli[1];

        $query = $this->getEntityManager()->createQueryBuilder('vp')
            ->delete(ValidationPeriod::class, 'vp')
        // TODO Probablement plus rapide avec des requêtes natives

        // Récupération des déclarations
        $declarations = $this->getEntityManager()->getRepository(ValidationPeriod::class)->createQueryBuilder('vp')
            ->where('vp.year = :year AND vp.month = :month AND vp.declarer = :person')
            ->setParameters([
                'year' => $year,
                'month' => $month,
                'person' => $person,
            ])
            ->getQuery();
            ->getQuery()->getResult();

        $query->execute();
        return true;
        /** @var ValidationPeriod $declaration */
        foreach ($declarations as $declaration){
            /** @var TimeSheet $ts */
            foreach ($declaration->getTimesheets() as $ts) {
                $ts->setValidationPeriod(null);
            }
            $this->getEntityManager()->remove($declaration);
        }
        $this->getEntityManager()->flush();

        return true;
    }

    /**