Commit 0a491d57 authored by Laurent Lecluse's avatar Laurent Lecluse
Browse files

Si un plafond bloquant est dépassé, on peut maintenant réduire le nombre...

Si un plafond bloquant est dépassé, on peut maintenant réduire le nombre d'heures et enregistrer le tout même si on ne repasse pas en-dessous du plafond.

Correction d'un bug en plus qui empêchait de contrôler corectement les plafonds reposant sur le calcul de la formule ou des tableaux de bord
parent e6533bd9
Loading
Loading
Loading
Loading
+6 −3
Original line number Diff line number Diff line
@@ -443,7 +443,7 @@ class ServiceController extends AbstractController
            } catch (\Exception $e) {
                $this->flashMessenger()->addErrorMessage($this->translate($e));
            }
            $this->getProcessusPlafond()->endTransaction($service->getIntervenant(), $typeVolumeHoraire);
            $this->getProcessusPlafond()->endTransaction($service->getIntervenant(), $typeVolumeHoraire, true);
        }

        return new MessengerViewModel;
@@ -492,7 +492,7 @@ class ServiceController extends AbstractController

        $form->get('service')->setIntervenant($intervenant);
        $form->get('service')->removeUnusedElements();

        $hDeb    = $entity->getVolumeHoraireListe()->getHeures();
        $request = $this->getRequest();
        if ($request->isPost()) {
            $form->setData($request->getPost());
@@ -508,9 +508,12 @@ class ServiceController extends AbstractController
                    } catch (\Exception $e) {
                        $this->flashMessenger()->addErrorMessage($this->translate($e));
                    }
                    $this->getProcessusPlafond()->endTransaction($entity->getIntervenant(), $typeVolumeHoraire);
                    $hFin = $entity->getVolumeHoraireListe()->getHeures();
                    $this->updateTableauxBord($entity->getIntervenant());
                    if (!$this->getProcessusPlafond()->endTransaction($entity->getIntervenant(), $typeVolumeHoraire, $hFin < $hDeb)) {
                        $this->updateTableauxBord($entity->getIntervenant());
                    }
                }
            } else {
                $this->flashMessenger()->addErrorMessage('La validation du formulaire a échoué. L\'enregistrement des données n\'a donc pas été fait.');
            }
+13 −11
Original line number Diff line number Diff line
@@ -141,7 +141,7 @@ class ServiceReferentielController extends AbstractController
        if (!$this->isAllowed($assertionEntity, Privileges::REFERENTIEL_EDITION)) {
            throw new \LogicException("Cette opération n'est pas autorisée.");
        }

        $hDeb    = $entity->getVolumeHoraireReferentielListe()->getHeures();
        $request = $this->getRequest();
        if ($request->isPost()) {
            $form->setData($request->getPost());
@@ -155,8 +155,11 @@ class ServiceReferentielController extends AbstractController
                } catch (\Exception $e) {
                    $this->flashMessenger()->addErrorMessage($this->translate($e));
                }
                $this->getProcessusPlafond()->endTransaction($intervenant, $typeVolumeHoraire);
                $hFin = $entity->getVolumeHoraireReferentielListe()->getHeures();
                $this->updateTableauxBord($intervenant);
                if (!$this->getProcessusPlafond()->endTransaction($intervenant, $typeVolumeHoraire, $hFin < $hDeb)) {
                    $this->updateTableauxBord($intervenant);
                }
            } else {
                $this->flashMessenger()->addErrorMessage('La validation du formulaire a échoué. L\'enregistrement des données n\'a donc pas été fait.');
            }
@@ -219,7 +222,6 @@ class ServiceReferentielController extends AbstractController
                    $this->getProcessusPlafond()->endTransaction($service->getIntervenant(), $typeVolumeHoraire);
                }
            }

        }

        return new MessengerViewModel;
@@ -255,7 +257,7 @@ class ServiceReferentielController extends AbstractController
            } catch (\Exception $e) {
                $this->flashMessenger()->addErrorMessage($this->translate($e));
            }
            $this->getProcessusPlafond()->endTransaction($service->getIntervenant(), $typeVolumeHoraire);
            $this->getProcessusPlafond()->endTransaction($service->getIntervenant(), $typeVolumeHoraire, true);
        }

        return new MessengerViewModel;
+8 −4
Original line number Diff line number Diff line
@@ -86,6 +86,7 @@ class VolumeHoraireController extends AbstractController
        }

        $volumeHoraireListe = new VolumeHoraireListe($service);
        $hDeb               = $volumeHoraireListe->getHeures();
        $vhlph              = new ListeFilterHydrator();
        $vhlph->setEntityManager($this->em());
        $vhlph->hydrate($this->params()->fromQuery() + $this->params()->fromPost(), $volumeHoraireListe);
@@ -97,17 +98,20 @@ class VolumeHoraireController extends AbstractController
        $form->setViewMNP($canViewMNP);
        $form->setEditMNP($canEditMNP);
        $form->build();
        $form->bindRequestSave($volumeHoraireListe, $this->getRequest(), function (VolumeHoraireListe $vhl) {
        $form->bindRequestSave($volumeHoraireListe, $this->getRequest(), function (VolumeHoraireListe $vhl) use ($hDeb) {
            try {
                $service = $vhl->getService();
                $this->getProcessusPlafond()->beginTransaction();
                $this->getServiceService()->save($service);
                $this->getProcessusPlafond()->endTransaction($service->getIntervenant(), $vhl->getTypeVolumeHoraire());
                $hFin = $vhl->getHeures();
                $this->updateTableauxBord($service->getIntervenant());
                if (!$this->getProcessusPlafond()->endTransaction($service->getIntervenant(), $vhl->getTypeVolumeHoraire(), $hFin < $hDeb)) {
                    $this->updateTableauxBord($service->getIntervenant());
                }
                $this->flashMessenger()->addSuccessMessage('Enregistrement effectué');
            } catch (\Exception $e) {
                $this->flashMessenger()->addErrorMessage($this->translate($e));
            }
            $this->updateTableauxBord($service->getIntervenant());
        });

        return compact('form');
@@ -136,7 +140,7 @@ class VolumeHoraireController extends AbstractController
            $this->getProcessusPlafond()->beginTransaction();
            $this->getServiceService()->save($service);
            $this->updateTableauxBord($service->getIntervenant());
            $this->getProcessusPlafond()->endTransaction($service->getIntervenant(), $volumeHoraireListe->getTypeVolumeHoraire());
            $this->getProcessusPlafond()->endTransaction($service->getIntervenant(), $volumeHoraireListe->getTypeVolumeHoraire(), true);
            $this->flashMessenger()->addSuccessMessage('Enregistrement effectué');
        } catch (\Exception $e) {
            $this->flashMessenger()->addErrorMessage($this->translate($e));
+8 −5
Original line number Diff line number Diff line
@@ -55,16 +55,19 @@ class PlafondProcessus implements EntityManagerAwareInterface
     *
     * @return bool
     */
    public function endTransaction(Intervenant $intervenant, TypeVolumeHoraire $typeVolumeHoraire): bool
    public function endTransaction(Intervenant $intervenant, TypeVolumeHoraire $typeVolumeHoraire, bool $isDiminution = false): bool
    {
        $hasBloquant = $this->controle($intervenant, $typeVolumeHoraire, true);
        if ($hasBloquant) {
        $this->getEntityManager()->flush();
        $hasBloquant = $this->controle($intervenant, $typeVolumeHoraire, !$isDiminution);
        if ($hasBloquant && !$isDiminution) {
            $this->getEntityManager()->rollback();

            return false;
        } else {
            $this->getEntityManager()->commit();
        }

        return $hasBloquant;
            return true;
        }
    }


+22 −22
Original line number Diff line number Diff line
@@ -243,8 +243,8 @@ class ServiceService extends AbstractEntityService
     *
     * @param Service $entity
     *
     * @throws Exception
     * @return Service
     * @throws Exception
     */
    public function save($entity)
    {
@@ -375,7 +375,7 @@ class ServiceService extends AbstractEntityService
    {
        $serviceElement = $this->getServiceElementPedagogique();

        list($qb, $alias) = $this->initQuery($qb, $alias);
        [$qb, $alias] = $this->initQuery($qb, $alias);
        $this->leftJoin($serviceElement, $qb, 'elementPedagogique');
        $serviceElement->finderByEtape($etape, $qb);

@@ -394,7 +394,7 @@ class ServiceService extends AbstractEntityService
     */
    public function finderByNiveauEtape(NiveauEtape $niveauEtape, QueryBuilder $qb = null, $alias = null)
    {
        list($qb, $alias) = $this->initQuery($qb, $alias);
        [$qb, $alias] = $this->initQuery($qb, $alias);
        if ($niveauEtape && $niveauEtape->getId() !== '-') {
            $serviceElement = $this->getServiceElementPedagogique();
            $serviceEtape   = $this->getServiceEtape();
@@ -419,7 +419,7 @@ class ServiceService extends AbstractEntityService
     */
    public function finderByTypeVolumeHoraire(TypeVolumeHoraire $typeVolumeHoraire, QueryBuilder $qb = null, $alias = null)
    {
        list($qb, $alias) = $this->initQuery($qb, $alias);
        [$qb, $alias] = $this->initQuery($qb, $alias);
        if ($typeVolumeHoraire) {
            $serviceVolumeHoraire = $this->getServiceVolumeHoraire();

@@ -442,7 +442,7 @@ class ServiceService extends AbstractEntityService
     */
    public function finderByEtatVolumeHoraire(EtatVolumeHoraire $etatVolumeHoraire, QueryBuilder $qb = null, $alias = null)
    {
        list($qb, $alias) = $this->initQuery($qb, $alias);
        [$qb, $alias] = $this->initQuery($qb, $alias);
        if ($etatVolumeHoraire) {
            $serviceVolumeHoraire = $this->getServiceVolumeHoraire();

@@ -470,7 +470,7 @@ class ServiceService extends AbstractEntityService
     */
    public function finderByComposante(Structure $structure, QueryBuilder $qb = null, $alias = null)
    {
        list($qb, $alias) = $this->initQuery($qb, $alias);
        [$qb, $alias] = $this->initQuery($qb, $alias);

        $serviceStructure          = $this->getServiceStructure();
        $serviceIntervenant        = $this->getServiceIntervenant();
@@ -503,7 +503,7 @@ class ServiceService extends AbstractEntityService
     */
    public function finderByStructureAff(Structure $structure, QueryBuilder $qb = null, $alias = null)
    {
        list($qb, $alias) = $this->initQuery($qb, $alias);
        [$qb, $alias] = $this->initQuery($qb, $alias);

        $serviceIntervenant = $this->getServiceIntervenant();

@@ -526,7 +526,7 @@ class ServiceService extends AbstractEntityService
     */
    public function finderByStructureEns(Structure $structure, QueryBuilder $qb = null, $alias = null)
    {
        list($qb, $alias) = $this->initQuery($qb, $alias);
        [$qb, $alias] = $this->initQuery($qb, $alias);

        $serviceElementPedagogique = $this->getServiceElementPedagogique();
        $this->join($serviceElementPedagogique, $qb, 'elementPedagogique', false, $alias);
@@ -549,7 +549,7 @@ class ServiceService extends AbstractEntityService
    {
        $role = $this->getServiceContext()->getSelectedIdentityRole();

        list($qb, $alias) = $this->initQuery($qb, $alias);
        [$qb, $alias] = $this->initQuery($qb, $alias);

        $this->join($this->getServiceIntervenant(), $qb, 'intervenant', false, $alias);
        $this->getServiceIntervenant()->finderByAnnee($this->getServiceContext()->getAnnee(), $qb);
@@ -573,7 +573,7 @@ class ServiceService extends AbstractEntityService
     */
    public function finderByTypeIntervenant(TypeIntervenant $typeIntervenant = null, QueryBuilder $qb = null, $alias = null)
    {
        list($qb, $alias) = $this->initQuery($qb, $alias);
        [$qb, $alias] = $this->initQuery($qb, $alias);
        if ($typeIntervenant) {
            $this->join($this->getServiceIntervenant(), $qb, 'intervenant', false, $alias);
            $this->getServiceIntervenant()->finderByType($typeIntervenant, $qb);