Commit 9966d26c authored by Antony Le Courtes's avatar Antony Le Courtes
Browse files

Refactoring reconduction centre cout et modulateur

- Refactoring des vues (Séparation vue modulateur et cc)
- Revue des templates
- Adaptation EtapeService.php
parent d1c877b2
Loading
Loading
Loading
Loading
+43 −32
Original line number Diff line number Diff line
@@ -35834,43 +35834,54 @@ FROM
  JOIN categorie_privilege cp ON cp.id = p.categorie_id
  LEFT JOIN statuts_roles sr ON sr.privilege_id = p.id',
    ),
    'V_RECONDUCTION_CC_MODULATEUR' => 
    'V_RECONDUCTION_CENTRE_COUT' => 
    array (
      'name' => 'V_RECONDUCTION_CC_MODULATEUR',
      'definition' => 'CREATE OR REPLACE FORCE VIEW V_RECONDUCTION_CC_MODULATEUR AS
WITH t AS (
      'name' => 'V_RECONDUCTION_CENTRE_COUT',
      'definition' => 'CREATE OR REPLACE FORCE VIEW V_RECONDUCTION_CENTRE_COUT AS
SELECT
  e.id                etape_id,
    e.annee_id          annee_id,
    e.structure_id      structure_id,
  e.libelle           etape_libelle,
    e.id                etape_id,
    e.code              etape_code,
  ep.id               element_pedagogique_id,
  ccep.centre_cout_id centre_cout_id,
  em.id                  element_modulateur_id,
  em.MODULATEUR_ID    modulateur_id,
  ccep.type_heures_id type_heures_id,
  ep.annee_id         annee_id,
  ep.code             code
    e.libelle           etape_libelle,
    cc1.id               centre_cout_id,
    ccep1.type_heures_id type_heures_id,
    ep1.code             ep_code,
    ep2.id              new_ep_id
FROM
	etape e
  JOIN element_pedagogique ep ON ep.etape_id = e.id AND ep.histo_destruction IS NULL
  LEFT JOIN centre_cout_ep    ccep ON ccep.element_pedagogique_id = ep.id AND ccep.histo_destruction IS NULL
  LEFT JOIN ELEMENT_MODULATEUR em ON em.ELEMENT_ID = ep.ID AND em.HISTO_DESTRUCTION  IS NULL
  LEFT JOIN source               s ON s.id = ccep.source_id AND s.importable = 0
	JOIN element_pedagogique    ep1 ON ep1.etape_id = e.id AND ep1.HISTO_DESTRUCTION IS NULL
	JOIN centre_cout_ep       ccep1 ON ccep1.element_pedagogique_id = ep1.id AND ccep1.HISTO_DESTRUCTION IS NULL
	JOIN centre_cout 		     cc1 ON ccep1.centre_cout_id = cc1.id AND cc1.HISTO_DESTRUCTION IS NULL
    JOIN source                   s ON s.id = ccep1.source_id AND s.importable = 0
	JOIN element_pedagogique    ep2 ON ep2.annee_id = ep1.annee_id+1  AND ep1.code = ep2.code AND ep2.HISTO_DESTRUCTION IS NULL
    LEFT JOIN centre_cout_ep  ccep2 ON ccep2.element_pedagogique_id = ep2.id AND ccep2.histo_destruction IS NULL AND ccep2.type_heures_id = ccep1.TYPE_HEURES_ID
 WHERE
 	e.histo_destruction IS NULL
  AND (ccep.id IS NULL OR s.id IS NOT NULL)
)
    AND ccep2.id IS NULL',
    ),
    'V_RECONDUCTION_MODULATEUR' => 
    array (
      'name' => 'V_RECONDUCTION_MODULATEUR',
      'definition' => 'CREATE OR REPLACE FORCE VIEW V_RECONDUCTION_MODULATEUR AS
SELECT
  t."ETAPE_ID",t."STRUCTURE_ID", t."ETAPE_LIBELLE", t."ETAPE_CODE", t."ELEMENT_PEDAGOGIQUE_ID",t."CENTRE_COUT_ID", t."ELEMENT_MODULATEUR_ID",t."MODULATEUR_ID", t."TYPE_HEURES_ID",t."ANNEE_ID",t."CODE",
  ep.id new_element_pedagogique_id,
  ccep.id new_centre_cout_ep_id,
  em.id new_element_modulateur_id
    e.annee_id          annee_id,
    e.structure_id      structure_id,
    e.id                etape_id,
    e.code              etape_code,
    e.libelle           etape_libelle,
	em1.modulateur_id   modulateur_id,
    ep1.code            ep_code,
    ep2.id              new_ep_id
FROM
  t
  LEFT JOIN element_pedagogique ep ON ep.annee_id = t.annee_id + 1 AND ep.code = t.code AND ep.histo_destruction IS NULL
  LEFT JOIN centre_cout_ep ccep ON ccep.element_pedagogique_id = ep.id AND ccep.centre_cout_id = t.centre_cout_id AND ccep.type_heures_id = t.type_heures_id
  LEFT JOIN ELEMENT_MODULATEUR em ON em.ELEMENT_ID = ep.ID AND em.HISTO_DESTRUCTION  IS NULL',
	etape e
	JOIN element_pedagogique     ep1 ON ep1.etape_id = e.id AND ep1.HISTO_DESTRUCTION IS NULL
	JOIN element_modulateur      em1 ON em1.element_id = ep1.id AND em1.histo_destruction IS NULL
	JOIN element_pedagogique     ep2 ON ep2.annee_id = ep1.annee_id+1  AND ep1.code = ep2.code AND ep2.HISTO_DESTRUCTION IS NULL
    LEFT JOIN element_modulateur em2 ON em2.element_id=ep2.id AND em2.histo_destruction IS NULL
 WHERE
 	e.histo_destruction IS NULL
    AND em2.id IS NULL',
    ),
    'V_REF_INTERVENANT' => 
    array (
+6 −6
Original line number Diff line number Diff line
@@ -221,7 +221,7 @@ class OffreFormationController extends AbstractController
            $datas = $request->getPost();
            //Reconduire les centres de coût des EP de l'étape.
            try {
                $etapesReconduites   = $this->getServiceEtape()->getEtapeReconduit($structure, 'centrecout');
                $etapesReconduites   = $this->getServiceEtape()->getEtapeCentreCoutReconductible($structure);
                $etapesReconduitesCc = [];
                if (isset($datas['etapes'])) {
                    foreach ($datas['etapes'] as $code) {
@@ -231,7 +231,7 @@ class OffreFormationController extends AbstractController
                    }
                }
                $result            = $this->getProcessusReconduction()->reconduireCCFormation($etapesReconduitesCc);
                $etapesReconduites = $this->getServiceEtape()->getEtapeReconduit($structure, 'centrecout');
                $etapesReconduites = $this->getServiceEtape()->getEtapeCentreCoutReconductible($structure);

                $this->flashMessenger()->addSuccessMessage("$result centre(s) de coût(s) ont été reconduit pour l'année prochaine. ");
            } catch (\Exception $e) {
@@ -240,7 +240,7 @@ class OffreFormationController extends AbstractController
        }

        if (empty($etapesReconduites) && !empty($structure)) {
            $etapesReconduites = $this->getServiceEtape()->getEtapeReconduit($structure, 'centrecout');
            $etapesReconduites = $this->getServiceEtape()->getEtapeCentreCoutReconductible($structure);
        }


@@ -270,7 +270,7 @@ class OffreFormationController extends AbstractController
        $request = $this->getRequest();
        if ($request->isPost()) {
            $datas             = $request->getPost();
            $etapesReconduites = $this->getServiceEtape()->getEtapeReconduit($structure);
            $etapesReconduites = $this->getServiceEtape()->getEtapeModulateurReconductible($structure);
            try {
                $etapesReconduitesCc = [];
                if (isset($datas['etapes'])) {
@@ -285,7 +285,7 @@ class OffreFormationController extends AbstractController

                $this->flashMessenger()->addSuccessMessage("$result modulateur(s) ont été reconduit pour l'année prochaine. ");

                $etapesReconduites = $this->getServiceEtape()->getEtapeReconduit($structure, 'modulateur');
                $etapesReconduites = $this->getServiceEtape()->getEtapeModulateurReconductible($structure);
            } catch (\Exception $e) {
                $this->flashMessenger()->addErrorMessage($e->getMessage());
            }
@@ -293,7 +293,7 @@ class OffreFormationController extends AbstractController

        //Récupération de toutes les étapes éligibles à la reconduction des coûts
        if (empty($etapesReconduites) && !empty($structure)) {
            $etapesReconduites = $this->getServiceEtape()->getEtapeReconduit($structure, 'modulateur');
            $etapesReconduites = $this->getServiceEtape()->getEtapeModulateurReconductible($structure);
        }


+35 −38
Original line number Diff line number Diff line
@@ -3,6 +3,7 @@
namespace Application\Processus;

use Application\Connecteur\Bdd\BddConnecteurAwareTrait;
use Application\Entity\Db\ElementModulateur;
use Application\Service\Traits\AnneeServiceAwareTrait;
use Application\Service\Traits\CentreCoutEpServiceAwareTrait;
use Application\Service\Traits\CheminPedagogiqueServiceAwareTrait;
@@ -12,6 +13,7 @@ use Application\Service\Traits\ElementPedagogiqueServiceAwareTrait;
use Application\Service\Traits\EtapeServiceAwareTrait;
use Application\Service\Traits\SourceServiceAwareTrait;
use Application\Service\Traits\VolumeHoraireEnsServiceAwareTrait;
use BddAdmin\Bdd;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\ParameterType;

@@ -208,32 +210,31 @@ class ReconductionProcessus extends AbstractProcessus
        SELECT 
            *            
        FROM 
            V_RECONDUCTION_CC_MODULATEUR
            V_RECONDUCTION_CENTRE_COUT
        WHERE
          ANNEE_ID = ?
          AND ETAPE_CODE IN (?)
          AND CENTRE_COUT_ID IS NOT NULL';
          AND ETAPE_CODE IN (?)';

        $connection    = $this->getEntityManager()->getConnection();
        $stmt          = $connection->executeQuery($sql, [$this->getServiceContext()->getAnnee()->getId(), $etapes_codes], [ParameterType::INTEGER, Connection::PARAM_STR_ARRAY]);
        $ccepN         = $stmt->fetchAll();
        $nbCCReconduit = 0;
        foreach ($ccepN as $key => $value) {
            if (empty($value['NEW_CENTRE_COUT_EP_ID'])) {
            //Récupération de la dernière incrémentation ID CCEP
            $nextSequence = $this->getNextSequence('CENTRE_COUT_EP_ID_SEQ');
            $stmt = $connection->insert('centre_cout_ep',
                ['id'                     => $nextSequence,
                 'centre_cout_id'         => $value['CENTRE_COUT_ID'],
                     'element_pedagogique_id' => $value['NEW_ELEMENT_PEDAGOGIQUE_ID'],
                 'element_pedagogique_id' => $value['NEW_EP_ID'],
                 'type_heures_id'         => $value['TYPE_HEURES_ID'],
                 'source_id'              => $this->getServiceSource()->getOse()->getId(),
                     'source_code'            => uniqid($value['CENTRE_COUT_ID'] . '_' . $value['TYPE_HEURES_ID'] . '_' . $value['NEW_ELEMENT_PEDAGOGIQUE_ID']),
                 'source_code'            => uniqid($value['CENTRE_COUT_ID'] . '_' . $value['TYPE_HEURES_ID'] . '_' . $value['NEW_EP_ID']),
                 'histo_createur_id'      => $this->getServiceContext()->getUtilisateur()->getId(),
                 'histo_modificateur_id'  => $this->getServiceContext()->getUtilisateur()->getId(),
                ]);

            $nbCCReconduit++;
            }

        }

        return $nbCCReconduit;
@@ -249,33 +250,29 @@ class ReconductionProcessus extends AbstractProcessus
        SELECT 
            *            
        FROM 
            V_RECONDUCTION_CC_MODULATEUR
            V_RECONDUCTION_MODULATEUR
        WHERE
            ANNEE_ID = ?
            AND ETAPE_CODE IN (?)
            AND ELEMENT_MODULATEUR_ID IS NOT NULL ';
            AND ETAPE_CODE IN (?)';

        $connection   = $this->getEntityManager()->getConnection();
        $stmt         = $connection->executeQuery($sql, [$this->getServiceContext()->getAnnee()->getId(), $etapes_codes], [ParameterType::INTEGER, Connection::PARAM_STR_ARRAY]);
        $mepN         = $stmt->fetchAll();
        $nbMReconduit = 0;


        foreach ($mepN as $key => $value) {
            if (empty($value['NEW_ELEMENT_MODULATEUR_ID'])) {
            //Récupération de la dernière incrémentation ID CCEP
            $nextSequence = $this->getNextSequence('ELEMENT_MODULATEUR_ID_SEQ');
                try {

            $stmt = $connection->insert('element_modulateur',
                ['id'                    => $nextSequence,
                         'element_id'            => $value['NEW_ELEMENT_PEDAGOGIQUE_ID'],
                 'element_id'            => $value['NEW_EP_ID'],
                 'modulateur_id'         => $value['MODULATEUR_ID'],
                 'histo_createur_id'     => $this->getServiceContext()->getUtilisateur()->getId(),
                 'histo_modificateur_id' => $this->getServiceContext()->getUtilisateur()->getId(),
                ]);
                $nbMReconduit++;
                } catch (\Exception $e) {
                    continue;
                }
            }
        }

        return $nbMReconduit;
+52 −22
Original line number Diff line number Diff line
@@ -63,49 +63,78 @@ class EtapeService extends AbstractEntityService

    /**
     * Retour uniquement les Etapes ayant été reconduites pour l'année universitaire suivante
     * et possédant des centres de coût à reconduire
     *
     * @return string
     */

    public function getEtapeReconduit($structure, $filter = null)
    public function getEtapeCentreCoutReconductible($structure)
    {
        $annee  = $this->getServiceContext()->getAnnee()->getId();


        $sql = '
        SELECT 
            count(*) as nb_centre_cout,
            etape_id,
            etape_libelle,
            etape_code,
            count(element_pedagogique_id) AS nb_ep_type_heure,
            count(DISTINCT element_modulateur_id) as nb_m,
            count(DISTINCT element_pedagogique_id) AS nb_ep,
            count(DISTINCT new_centre_cout_ep_id) AS nb_cc_ep,
            count(DISTINCT new_element_modulateur_id) AS nb_m_ep
            etape_libelle
        FROM 
            V_RECONDUCTION_CC_MODULATEUR 
            V_RECONDUCTION_CENTRE_COUT 
        WHERE
            annee_id = :annee
            AND new_element_pedagogique_id IS NOT NULL
            AND structure_id = '  . $structure->getId();

        if(!empty($filter))
        {
            if($filter == 'centrecout')
            {
                $sql .= ' AND  centre_cout_id IS NOT NULL';
            }
            if($filter == 'modulateur')
        $sql .= 'GROUP BY
                   etape_id,
                   etape_code,
                   etape_libelle
                ORDER BY etape_id ASC';

        $stmt = $this->getEntityManager()->getConnection()->prepare($sql);
        $stmt->bindParam(':annee', $annee);
        $stmt->execute();
        $result = $stmt->fetchAll();
        $etapes = [];
        foreach($result as $etape)
        {
                $sql .= ' AND element_modulateur_id IS NOT NULL';
            $etapes[$etape['ETAPE_CODE']] = $etape;
        }

        return $etapes;
    }


    /**
     * Retour uniquement les Etapes ayant été reconduites pour l'année universitaire suivante
     * et possédant des modulateurs à reconduire
     *
     * @return string
     */

    public function getEtapeModulateurReconductible($structure)
    {
        $annee  = $this->getServiceContext()->getAnnee()->getId();


        $sql = '
        SELECT 
            count(*) as nb_modulateur,
            etape_id,
            etape_code,
            etape_libelle
        FROM 
            V_RECONDUCTION_MODULATEUR 
        WHERE
            annee_id = :annee
            AND structure_id = '  . $structure->getId();

        $sql .= 'GROUP BY
                   etape_id,
            etape_libelle,
            etape_code
                   etape_code,
                   etape_libelle
                ORDER BY etape_id ASC';

        $stmt = $this->getEntityManager()->getConnection()->prepare($sql);
        $stmt->bindParam(':annee', $annee);
        $stmt->execute();
@@ -121,6 +150,7 @@ class EtapeService extends AbstractEntityService




    /**
     *
     * @param \Application\Entity\NiveauEtape $niveau
+3 −3
Original line number Diff line number Diff line
@@ -52,7 +52,7 @@ echo $this->messenger()->addCurrentMessagesFromFlashMessenger()->addMessagesFrom
        <tbody>
        <tr>
            <td colspan="6" style="text-align: center;">
                Aucune formation disponible
                Aucune centre de cout à reconduire
            </td>
        </tr>
        </tbody>
@@ -75,11 +75,11 @@ echo $this->messenger()->addCurrentMessagesFromFlashMessenger()->addMessagesFrom
            <?php foreach ($etapesReconduites as $er): ?>
                <tr>
                    <td>
                        <?= ($er['NB_EP']-$er['NB_CC_EP'] <= 0)?'<input disabled="disabled" title="Aucun centre de coût à reconduire" class="checkbox-element" type="checkbox" name="etapes[]" value="'.$er['ETAPE_CODE'].'">':'<input class="checkbox-element" type="checkbox" name="etapes[]" value="'.$er['ETAPE_CODE'].'">'; ?>
                        <input class="checkbox-element" type="checkbox" name="etapes[]" value="<?= $er['ETAPE_CODE'] ?>">
                    </td>
                    <td><?= $er['ETAPE_CODE']; ?></td>
                    <td><?= $er['ETAPE_LIBELLE']; ?></td>
                    <td><?= ($er['NB_EP_TYPE_HEURE']-$er['NB_CC_EP'] <= 0)?'Aucun centre de coût à reconduire':$er['NB_EP_TYPE_HEURE']-$er['NB_CC_EP']; ?></td>
                    <td><?= $er['NB_CENTRE_COUT']; ?></td>
                </tr>
            <?php endforeach; ?>
            </tbody>
Loading