Commit c8b3fb79 authored by Florian Joriot's avatar Florian Joriot
Browse files

Derniere correction creation et validation

parent f76acf9b
Loading
Loading
Loading
Loading
+2 −2
Changes for module/Contrat/src/Controller/ContratController.php: 2 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -262,8 +262,8 @@ class ContratController extends AbstractController
            return new MessengerViewModel;
        }

        $volumeHorairesContrat = $this->getServiceTblContrat()->getInformationContratById($contrat->getId());
        $contrat               = $this->getProcessusContrat()->creer($contrat, $volumeHorairesContrat);
        $tblContratContrat = $this->getServiceTblContrat()->getInformationContratById($contrat->getId());
        $contrat               = $this->getProcessusContrat()->creer($contrat, $tblContratContrat);

        if ($this->getRequest()->isPost()) {
            try {
+46 −64
Changes for module/Contrat/src/Processus/ContratProcessus.php: 46 added lines, 64 removed lines.
Original line number Diff line number Diff line
@@ -63,13 +63,12 @@ class ContratProcessus extends AbstractProcessus
     *
     * @return TblContrat[]
     */
    public function getVolumeHoraireTblContrat(string $uuid): array
    public function getVolumesHorairesTblContrat(string $uuid): array
    {
        $tblContrats = [];
        $query = $this->getEntityManager()->createQuery(
            'SELECT tblc, vh
                 FROM ' . TblContrat::class . ' tblc
                 JOIN tblc.volumeHoraire vh
                 left join tblc.volumesHoraires vhs WITH vhs.uuid = tblc.uuid
                 WHERE tblc.uuid = :uuid'
        );
        $query->setParameter('uuid', $uuid);
@@ -111,7 +110,7 @@ class ContratProcessus extends AbstractProcessus
        $query       = $this->getEntityManager()->createQuery(
            'SELECT tblc, vhm
                 FROM ' . TblContrat::class . ' tblc
                 JOIN tblc.volumeHoraireMission vhm
                left join tblc.volumesHoraires vhs WITH vhs.uuid = tblc.uuid
                 WHERE tblc.uuid = :uuid'
        );
        $query->setParameter('uuid', $uuid);
@@ -182,66 +181,6 @@ class ContratProcessus extends AbstractProcessus



    /**
     * Enregistrement du contrat ET liaison aux volumes horaires correspondants
     *
     * @param Contrat $contrat
     *
     * @return $this
     * @throws ORMException
     * @throws OptimisticLockException
     */
    public function enregistrer(Contrat $contrat, string $uuid): self
    {
        if ($contrat->getId()) {
            throw new LogicException('Le contrat existe déjà. Il ne peut pas être recréé');
        }

        // on sauvegarde le contrat
        $this->getServiceContrat()->save($contrat);

        // on récupère les services non contractualisés et on la place les VH correspondants dans le contrat
        $tblContrats = $this->getVolumeHoraireTblContrat($uuid);
        $this->getORMEventListenersHistoriqueListener()->setEnabled(false);
        foreach ($tblContrats as $tblContrat) {
            $vh = $tblContrat->getVolumeHoraire();
            if ($vh != null) {
                $vh->setContrat($contrat);
                $this->getEntityManager()->persist($vh);
            }
        }

        // on récupère les services referentiel non contractualisés et on la place les VHR correspondants dans le contrat
        $tblContrats = $this->getVolumeHoraireRefTblContrat($uuid);
        $this->getORMEventListenersHistoriqueListener()->setEnabled(false);
        foreach ($tblContrats as $tblContrat) {
            $vhr = $tblContrat->getVolumeHoraireRef();
            if ($vhr != null) {
                $vhr->setContrat($contrat);
                $this->getEntityManager()->persist($vhr);
            }
        }

        // on récupère les heures de mission et on les places dans le contrat
        $tblContrats = $this->getVolumeHoraireMissionTblContrat($uuid);
        $this->getORMEventListenersHistoriqueListener()->setEnabled(false);
        foreach ($tblContrats as $tblContrat) {
            $vhm = $tblContrat->getVolumeHoraireMission();
            if ($vhm != null) {
                $vhm->setContrat($contrat);
                $this->getEntityManager()->persist($vhm);
            }
        }


        $this->getORMEventListenersHistoriqueListener()->setEnabled(true);
        $this->getEntityManager()->flush();

        return $this;
    }



    /**
     * Suppression (historisation) d'un projet de contrat/avenant.
     *
@@ -302,6 +241,7 @@ class ContratProcessus extends AbstractProcessus
            ->setStructure($contrat->getStructure());

        $this->getServiceValidation()->save($validation);
        $contrat->setValidation($validation);
        $this->getServiceContrat()->save($contrat);

        return $validation;
@@ -325,6 +265,48 @@ class ContratProcessus extends AbstractProcessus



    /**
     * Enregistrement du contrat ET liaison aux volumes horaires correspondants
     *
     * @param Contrat $contrat
     *
     * @return $this
     * @throws ORMException
     * @throws OptimisticLockException
     */
    public function enregistrer(Contrat $contrat, ?string $uuid = null): self
    {
        if ($contrat->getId()) {
            throw new LogicException('Le contrat existe déjà. Il ne peut pas être recréé');
        }

        // on sauvegarde le contrat
        $this->getServiceContrat()->save($contrat);
        $this->getORMEventListenersHistoriqueListener()->setEnabled(false);

        $tblContrat = $this->getServiceTblContrat()->getInformationContratByUuid($uuid);

        $volumesHoraires = $tblContrat->getVolumesHoraires();
        foreach ($volumesHoraires as $tblContratVolumesHoraire) {
            $volumeHoraire = $tblContratVolumesHoraire->getVolumeHoraire()
                ?: $tblContratVolumesHoraire->getVolumeHoraireRef()
                    ?: $tblContratVolumesHoraire->getVolumeHoraireMission();

            if ($volumeHoraire !== null) {
                $volumeHoraire->setContrat($contrat);
                $this->getEntityManager()->persist($volumeHoraire);
            }
        }


        $this->getORMEventListenersHistoriqueListener()->setEnabled(true);
        $this->getEntityManager()->flush();

        return $this;
    }



    /**
     * Requalification d'un contrat en avenant ou d'un avenant en contrat
     *
+2 −5
Changes for module/Contrat/src/Service/TblContratService.php: 2 added lines, 5 removed lines.
Original line number Diff line number Diff line
@@ -119,11 +119,8 @@ class TblContratService extends AbstractEntityService

        $dql = 'SELECT tblc
        FROM ' . TblContrat::class . ' tblc
        JOIN tblc.typeContrat tc
        JOIN tblc.intervenant i
        LEFT JOIN tblc.structure s
        LEFT JOIN tblc.contratParent cp
        WHERE tblc.uuid = :uuid
        JOIN tblc.contrat c
        WHERE c.id = :id
        AND tblc.actif = 1
        AND tblc.volumeHoraireIndex = 0';

+1 −1
Changes for module/Contrat/view/contrat/contrat/index.phtml: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -68,7 +68,7 @@ echo $this->messenger() ?>
                    <td>
                        <?php if ($canCreer): ?>
                            <a class="btn btn-primary"
                               href="<?= $this->url('contrat/creer', ['intervenant' => $intervenant->getId(), 'uuid' => $tblContrat->getUuid()]) ?>]); ?>">
                               href="<?= $this->url('contrat/creer', ['intervenant' => $intervenant->getId(), 'uuid' => $tblContrat->getUuid()]) ?>">
                                <i class="fas fa-file"></i>Créer
                                un
                                <?php if ($contratDirect): ?>