Commit c413bd8a authored by Laurent Lecluse's avatar Laurent Lecluse
Browse files

Merge branch 'b19' of https://git.unicaen.fr/open-source/OSE into b19

parents 3b107b9c 14b2dd6e
Loading
Loading
Loading
Loading
+30 −7
Original line number Diff line number Diff line
@@ -12,7 +12,10 @@ ini_set('memory_limit', '-1');
$importDirectory = $osedir . 'cache/employeurs/';
$importArchive = 'employeurs.tar.gz';
$importFilePath = $importDirectory . $importArchive;
if (!file_exists($importDirectory)) {
    mkdir($importDirectory);
}

if (file_exists($importFilePath)) {
    unlink($importFilePath);
}
@@ -23,16 +26,30 @@ if (!file_exists($importFilePath)) {
    $c->printDie("L'archive $importArchive manquante");
}
//On vérifie que le répertoire import contient uniquement l'archive et aucun autre CSV

$listFiles = preg_grep('~\.(csv)$~', scandir($importDirectory));
if (count($listFiles) > 0) {
    $c->printDie("Merci de supprimer les fichiers CSV présents dans le dossier $importDirectory");
}
//Extraction du PharData
//$phar = new PharData($importFilePath);
//$phar->extractTo($importDirectory);
$phar = new PharData($importFilePath);
$phar->extractTo($importDirectory);
exec('cd ' . $importDirectory . ' && tar -xvf ' . $importFilePath);
//Verification si des SIRET sont déjà chargé en base
$bdd = $oa->getBdd();

//On vérifie si la source INSEE existe dans OSE

$haveAlreadyInseeSource = $bdd->select("SELECT * FROM source WHERE code='INSEE'", [], ['fetch' => $bdd::FETCH_ONE]);
if (!($haveAlreadyInseeSource)) {
    $idSource = $bdd->sequenceNextVal('SOURCE_ID_SEQ');
    $bdd->exec("INSERT INTO source (id, code, libelle, importable) VALUES ($idSource, 'INSEE', 'INSEE', 1)");
    //Le source INSEE n'existe pas encore, donc on migre tout ce qui est source OSE vers source INSEE
    $bdd->exec("UPDATE employeur SET source_id = $idSource");
} else {
    $idSource = $haveAlreadyInseeSource['ID'];
}

//$haveAlreadySiret     = $bdd->select("SELECT siret FROM employeur e WHERE siret IS NOT null FETCH FIRST 5 ROWS ONLY", [], ['fetch' => $bdd::FETCH_ONE]);
$haveAlreadySiret = $bdd->select("SELECT siret FROM (SELECT siret, rownum AS rn FROM employeur e WHERE siret IS NOT NULL) e WHERE e.rn < 10", [], ['fetch' => $bdd::FETCH_ONE]);
$haveAlreadyEmployeur = $bdd->select("SELECT * FROM employeur e");
@@ -40,6 +57,7 @@ $haveAlreadyEmployeur = $bdd->select("SELECT * FROM employeur e");

//récupération de la liste des fichiers CSV
$listFiles = preg_grep('~\.(csv)$~', scandir($importDirectory));

$nbFiles = count($listFiles);
$i = 1;
$c->println("Nombre de fichier à charger : $nbFiles", $c::COLOR_LIGHT_GREEN);
@@ -50,11 +68,15 @@ foreach ($listFiles as $file) {
    $num = str_replace('.csv', '', $file);

    $c->println("Chargement du fichier employeur N° $i sur $nbFiles");

    $csvFile = fopen($importDirectory . $file, "r");

    $row = 0;
    $datas = [];

    while (($data = fgetcsv($csvFile, 1000, ",")) !== false) {


        /*
        * $data[0] = Siren
        * $data[1] = Etat Administratif
@@ -115,7 +137,7 @@ foreach ($listFiles as $file) {
        $data['RAISON_SOCIALE'] = $raisonSociale;
        $data['NOM_COMMERCIAL'] = $nomCommercial;
        $data['SOURCE_CODE'] = $siret;
        $data['SOURCE_ID'] = $oseSource;
        $data['SOURCE_ID'] = $idSource;
        $data['IDENTIFIANT_ASSOCIATION'] = $identifiantAssociation;
        $data['HISTO_DESTRUCTEUR_ID'] = null;
        $data['HISTO_DESTRUCTION'] = null;
@@ -123,8 +145,8 @@ foreach ($listFiles as $file) {
        $data['CRITERE_RECHERCHE'] = reduce($raisonSociale . ' ' . $nomCommercial . ' ' . $siren . ' ' . $siret);
        $datas[] = $data;
        $options['histo-user-id'] = $oseId;
        $options['where'] = 'SIREN LIKE \'' . $num . '%\' AND SOURCE_ID = (SELECT id FROM source WHERE code = \'OSE\') AND SIREN NOT IN (\'999999999\', \'000000000000\')';
        $options['soft-delete'] = false;
        $options['where'] = 'SIREN LIKE \'' . $num . '%\' AND SOURCE_ID = (SELECT id FROM source WHERE code = \'INSEE\') AND SIREN NOT IN (\'999999999\', \'000000000000\')';
        $options['delete'] = false;
    }

    $i++;
@@ -135,13 +157,14 @@ foreach ($listFiles as $file) {
        $tableEmployeur->merge($datas, 'SIRET', $options);
    }
}

//On remet l'insertion de l'employeur étrangé
$data = [];
$data['SIREN'] = '999999999';
$data['RAISON_SOCIALE'] = 'EMPLOYEUR ETRANGÉ';
$data['NOM_COMMERCIAL'] = 'EMPLOYEUR ETRANGÉ';
$data['SOURCE_CODE'] = '999999999';
$data['SOURCE_ID'] = $oseSource;
$data['SOURCE_ID'] = $idSource;
$data['IDENTIFIANT_ASSOCIATION'] = null;
$data['HISTO_DESTRUCTEUR_ID'] = null;
$data['HISTO_DESTRUCTION'] = null;
@@ -159,7 +182,7 @@ $data['SIREN'] = '000000000000';
$data['RAISON_SOCIALE'] = 'Employeur non présent dans la liste';
$data['NOM_COMMERCIAL'] = 'Employeur non présent dans la liste';
$data['SOURCE_CODE'] = '000000000000';
$data['SOURCE_ID'] = $oseSource;
$data['SOURCE_ID'] = $idSource;
$data['IDENTIFIANT_ASSOCIATION'] = null;
$data['HISTO_DESTRUCTEUR_ID'] = null;
$data['HISTO_DESTRUCTION'] = null;
+6 −4
Original line number Diff line number Diff line
CREATE OR REPLACE FORCE VIEW V_INTERVENANT_HISTORIQUE AS
CREATE
OR REPLACE FORCE VIEW V_INTERVENANT_HISTORIQUE AS
WITH historique AS (
--Initialisation des données personnelles
    SELECT d.intervenant_id                              intervenant_id,
@@ -94,8 +95,9 @@ UNION ALL
SELECT s.intervenant_id                                                                          intervenant_id,
       '3 - Service prévisionnel et/ou service référentiel'                                                              categorie,
       'Modification/Ajout du service prévisionnel pour la composante ' || MAX(st.libelle_court) label,
       MAX(vh.histo_creation)                                                                histo_date,
       MAX(vh.histo_createur_id)                                                             KEEP (dense_rank FIRST ORDER BY vh.histo_modification DESC)   histo_createur_id, MAX(u.display_name) KEEP (dense_rank FIRST ORDER BY vh.histo_modification DESC)    histo_user,
       MAX(s.histo_creation)                                                                histo_date,
       MAX(s.histo_createur_id)                                                             KEEP (dense_rank FIRST ORDER BY s.histo_modification DESC)   histo_createur_id,
       MAX(u.display_name) KEEP (dense_rank FIRST ORDER BY s.histo_modification DESC)    histo_user,
       'glyphicon glyphicon-ok'                           icon,
       3                                                                                         ordre
FROM volume_horaire vh
@@ -105,7 +107,7 @@ FROM volume_horaire vh
         JOIN type_volume_horaire tvh ON tvh.id = vh.type_volume_horaire_id AND tvh.code = 'PREVU'
         JOIN periode p ON p.id = vh.periode_id
         JOIN type_intervention ti ON ti.id = vh.type_intervention_id
         JOIN utilisateur u ON u.id = vh.histo_modificateur_id
         JOIN utilisateur u ON u.id = s.histo_modificateur_id
         LEFT JOIN motif_non_paiement mnp ON mnp.id = vh.motif_non_paiement_id
GROUP BY s.intervenant_id, ep.structure_id

+29 −1
Original line number Diff line number Diff line
@@ -20,6 +20,34 @@ return [
                    ],
                ],
                'may_terminate' => true,
                'child_routes'  => [
                    'saisie'    => [
                        'type'          => 'Segment',
                        'options'       => [
                            'route'       => '/saisie[/:employeur]',
                            'constraints' => [
                                'employeur' => '[0-9]*',
                            ],
                            'defaults'    => [
                                'action' => 'saisie',
                            ],
                        ],
                        'may_terminate' => true,
                    ],
                    'supprimer' => [
                        'type'          => 'Segment',
                        'options'       => [
                            'route'       => '/supprimer/:employeur',
                            'constraints' => [
                                'employeur' => '[0-9]*',
                            ],
                            'defaults'    => [
                                'action' => 'supprimer',
                            ],
                        ],
                        'may_terminate' => true,
                    ],
                ],
            ],
            'employeur-search' => [
                'type'          => 'Literal',
@@ -79,7 +107,7 @@ return [
            PrivilegeController::class      => [
                [
                    'controller' => 'Application\Controller\Employeur',
                    'action'     => ['index', 'recherche-json'],
                    'action'     => ['index', 'recherche-json', 'saisie'],
                    'privileges' => Privileges::REFERENTIEL_COMMUN_EMPLOYEUR_VISUALISATION,
                ],
            ],
+36 −1
Original line number Diff line number Diff line
@@ -3,6 +3,8 @@
namespace Application\Controller;


use Application\Entity\Db\Employeur;
use Application\Form\Employeur\Traits\EmployeurSaisieFormAwareTrait;
use Application\Service\Traits\EmployeurServiceAwareTrait;
use Laminas\View\Model\JsonModel;

@@ -15,6 +17,7 @@ class EmployeurController extends AbstractController
{

    use EmployeurServiceAwareTrait;
    use EmployeurSaisieFormAwareTrait;

    public function indexAction()
    {
@@ -25,6 +28,39 @@ class EmployeurController extends AbstractController
        return compact('employeurs');
    }

    public function saisieAction()
    {
        $employeur = $this->getEvent()->getParam('employeur');

        if (empty($employeur)) {
            $title = "Ajout d'un nouvel employeur";
            $employeur = $this->getServiceEmployeur()->newEntity();
        } else {
            $title = "Édition d'un employeur";
        }

        $form = $this->getFormEmployeurSaisie();


        $form->bindRequestSave($employeur, $this->getRequest(), function () use ($employeur, $form) {
            /**
             * @var Employeur $employeur
             */
            $employeur->setCritereRecherche($employeur->getRaisonSociale() . ' ' . $employeur->getNomCommercial() . ' ' . $employeur->getSiret());
            $employeur->setSourceCode($employeur->getSiret());
            $this->getServiceEmployeur()->save($employeur);
            $this->flashMessenger()->addSuccessMessage(
                "Ajout réussi"
            );
        });

        return compact('form', 'title');
    }

    public function supprimerAction()
    {
        return true;
    }


    public function rechercheAction()
@@ -42,7 +78,6 @@ class EmployeurController extends AbstractController
    }



    public function rechercheJsonAction()
    {
        $critere = $this->params()->fromPost('critere');
+1 −0
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@ class EmployeurControllerFactory
     */
    public function __invoke(ContainerInterface $container, $requestedName, $options = null)
    {

        $controller = new EmployeurController();

        return $controller;
Loading