Commit 941c2f2a authored by Antony Le Courtes's avatar Antony Le Courtes
Browse files

Refactoring export offre de formation en état de sortie

parent 545eeff8
Loading
Loading
Loading
Loading
Loading
+45 −0
Changes for data/ddl/view/V_EXPORT_FORMATION.sql: 45 added lines, 0 removed lines.
Original line number Diff line number Diff line
CREATE OR REPLACE FORCE VIEW V_EXPORT_FORMATION AS
SELECT
            MAX(e.annee_id)                                       annee_id,
            MAX(s.id)												                      structure_id,
            MAX(s.ids)												                    structure_ids,
            MAX(s.libelle_court)             						          structure,
            MAX(e.code)												                    code_formation,
            MAX(e.libelle) 											                  libelle_formation,
            MAX(e.id)												                      etape_id,
            MAX(vnf.libelle_long)									                niveau,
            MAX(ep.code) 											                    code_enseignement,
            MAX(ep.libelle) 										                  libelle_enseignement,
            MAX(d.source_code)			    						              code_discipline,
            MAX(d.libelle_long)										                libelle_discipline,
            MAX(p.libelle_long)      								              periode,
            MAX(ep.taux_foad)										                  foad,
            MAX(ep.fi) 												                    fi,
            MAX(ep.fa) 												                    fa,
            MAX(ep.fc) 												                    fc,
            COALESCE(MAX(ef.fi),0)									              effectif_fi,
            COALESCE(MAX(ef.fa),0)									              effectif_fa,
            COALESCE(MAX(ef.fc),0)									              effectif_fc,
            SUM(CASE WHEN ti.code = 'CM' THEN vhe.heures END) 		heures_cm,
            SUM(CASE WHEN ti.code = 'CM' THEN vhe.groupes END) 		nb_groupe_cm,
            SUM(CASE WHEN ti.code = 'TD' THEN vhe.heures END) 		heures_td,
            SUM(CASE WHEN ti.code = 'TD' THEN vhe.groupes END) 		nb_groupe_td,
            SUM(CASE WHEN ti.code = 'TP' THEN vhe.heures END) 		heures_tp,
            SUM(CASE WHEN ti.code = 'TP' THEN vhe.groupes END) 		nb_groupe_tp
        FROM
            etape e
        LEFT JOIN STRUCTURE s ON s.id = e.structure_id
        LEFT JOIN v_etape_niveau_formation venf ON e.id = venf.etape_id
        LEFT JOIN v_niveau_formation vnf ON vnf.id = venf.niveau_formation_id
        LEFT JOIN element_pedagogique ep ON ep.etape_id = e.id AND ep.histo_destruction IS NULL
        LEFT JOIN discipline d ON d.id = ep.discipline_id
        LEFT JOIN periode p ON p.id = ep.periode_id
        LEFT JOIN effectifs ef ON ef.element_pedagogique_id = ep.id
        LEFT JOIN volume_horaire_ens vhe ON vhe.element_pedagogique_id = ep.id
        LEFT JOIN type_intervention ti ON ti.id = vhe.type_intervention_id
        WHERE 
            e.histo_destruction IS NULL
        GROUP BY 
            ep.id

+29 −58
Changes for module/OffreFormation/src/Service/OffreFormationService.php: 29 added lines, 58 removed lines.
Original line number Diff line number Diff line
@@ -5,6 +5,7 @@ namespace OffreFormation\Service;
use Application\Service\AbstractEntityService;
use Application\Service\Traits\AnneeServiceAwareTrait;
use Application\Service\Traits\ContextServiceAwareTrait;
use Application\Service\Traits\EtatSortieServiceAwareTrait;
use Application\Service\Traits\LocalContextServiceAwareTrait;
use Application\Service\Traits\SourceServiceAwareTrait;
use Lieu\Entity\Db\Structure;
@@ -25,6 +26,7 @@ class OffreFormationService extends AbstractEntityService
    use SourceServiceAwareTrait;
    use AnneeServiceAwareTrait;
    use LocalContextServiceAwareTrait;
    use EtatSortieServiceAwareTrait;


    public function getEntityClass()
@@ -295,10 +297,33 @@ class OffreFormationService extends AbstractEntityService

    public function generateCsvExport(?Structure $structure, ?NiveauEtape $niveau, ?Etape $etape): CsvModel
    {
        /* Préparation et affichage */
        $etatSortie = $this->getServiceEtatSortie()->getRepo()->findOneBy(['code' => 'export-offre-formation']);

        $elements = $this->getNeep($structure, $niveau, $etape)[2];
        $fileName = 'Export-offre-formation - ' . date('dmY') . '.csv';

        $headers = [
        //$filters             = $recherche->getFilters();
        $filters['ANNEE_ID'] = '2025';
        /*if ($structure) {
            $filters['STRUCTURE_AFF_IDS OR STRUCTURE_ENS_IDS'] = $structure->idsFilter();
        }

        $options = [
            'annee'               => $annee->getLibelle(),
            'type_volume_horaire' => $recherche->getTypeVolumeHoraire()->getLibelle(),
            'etat_volume_horaire' => $recherche->getEtatVolumeHoraire()->getLibelle(),
            'composante'          => $recherche->getStructureAff() ? $recherche->getStructureAff()->getLibelleCourt() : 'Toutes',
            'type_intervenant'    => $recherche->getTypeIntervenant() ? $recherche->getTypeIntervenant()->getLibelle() : 'Tous intervenants',
        ];*/


        $csv = $this->getServiceEtatSortie()->genererCsv($etatSortie, $filters, []);
        $csv->setFilename($fileName);


        //$elements = $this->getNeep($structure, $niveau, $etape)[2];

        /*$headers = [
            'Structure',
            'Code formation',
            'Libellé formation',
@@ -315,65 +340,11 @@ class OffreFormationService extends AbstractEntityService
            'Effectifs FI actuels',
            'Effectifs FA actuels',
            'Effectifs FC actuels',
        ];

        $typesIntervention = ['CM', 'TD', 'TP'];
        foreach ($elements as $element) {
            foreach ($element->getVolumeHoraireEns() as $vhe) {
                if (!in_array($vhe->getTypeIntervention()->getCode(), $typesIntervention)) {
                    $typesIntervention[] = $vhe->getTypeIntervention()->getCode();
                }
            }
        }
        ];*/

        foreach ($typesIntervention as $type) {
            $headers[] = 'Nbr groupes ' . $type;
            $headers[] = 'Nbr heures ' . $type;
        }
        $csvModel = new CsvModel();
        return $csv;

        $csvModel->setHeader($headers);

        foreach ($elements as $element) {
            $typeIntervention = $element->getTypeIntervention();
            $typeInterventionValues = [];
            foreach ($typesIntervention as $type) {
                $typeInterventionValues[$type] = 0;
                $typeInterventionValues[$type . 'Groupe'] = 0;
            }

            foreach ($element->getVolumeHoraireEns() as $vhe) {
                $typeInterventionValues[$vhe->getTypeIntervention()->getCode()] = (!empty($vhe->getHeures())) ? $vhe->getHeures() : '0';
                $typeInterventionValues[$vhe->getTypeIntervention()->getCode() . 'Groupe'] = (!empty($vhe->getGroupes())) ? $vhe->getGroupes() : '0';
            }
            $etape = $element->getEtape();
            $effectifs = $element->getEffectifs();
            $discipline = $element->getDiscipline();
            $lineValues = [
                $etape->getStructure()->getLibelleCourt(),
                $etape->getCode(),
                $etape->getLibelle(),
                $etape->getNiveauToString(),
                $element->getCode(),
                $element->getLibelle(),
                $discipline ? $discipline->getSourceCode() : null,
                $discipline ? $discipline->getLibelleLong() : null,
                $element->getPeriode(),
                $element->getTauxFoad(),
                $element->getTauxFi(),
                $element->getTauxFa(),
                $element->getTauxFc(),
                $effectifs ? $effectifs->getFi() : null,
                $effectifs ? $effectifs->getFa() : null,
                $effectifs ? $effectifs->getFc() : null,
            ];

            $csvModel->addLine(array_merge($lineValues, $typeInterventionValues));
        }
        $uniqueId = date('Y-m-d-H-i');
        $csvModel->setFilename('offre-de-formation-' . $uniqueId . '.csv');

        return $csvModel;
    }

}