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

Merge branch 'master' of https://git.unicaen.fr/open-source/OSE into ll-optimisation_-chargens

parents 26530c6d 1479372b
Loading
Loading
Loading
Loading
+10 −282
Original line number Diff line number Diff line
@@ -8,292 +8,20 @@
 * @var $viewFile   string
 */

$si = $container->get(\Application\Service\IntervenantService::class);
//$i = $si->get(193437);


/** @var \ExportRh\Service\ExportRhService $erhs */
$erhs = $container->get(\ExportRh\Service\ExportRhService::class);


class Iparser
{
    public  $bdd;
$p = $erhs->getIntervenantExportParams();
var_dump($p);

    public  $data        = [];
//$p->prenom = true;

    public  $actions     = [];
$erhs->saveIntervenantExportParams();

    public  $allActions  = [];

    public  $fncs        = [];

    public  $fncsStatuts = [];

    private $cFnc;

    private $cAnnee;

    private $cCode;

    public  $statuts     = [];



    public function fetch()
    {
        $filter = "
        AND annee_id IN (2020)
        --AND code = 1002
        ";

        $bdd = adminBdd();

        $sts = $bdd->select('select si.id, ti.libelle || \' <br /><br /> \' || si.libelle libelle FROM statut_intervenant si join type_intervenant ti on ti.id = si.type_intervenant_id');
        foreach ($sts as $st) {
            $this->statuts[$st['ID']] = $st['LIBELLE'];
        }

        $sql = "

        with idata as (select 
           intervenant_id, listagg(cc.t, ', ') within group( order by cc.t) tbls
        from 
          (
                  select count(*) || ' AGREMENT'                t, intervenant_id from AGREMENT where histo_destruction is null GROUP BY intervenant_id
        union all select count(*) || ' CONTRAT'                 t, intervenant_id from CONTRAT where histo_destruction is null GROUP BY intervenant_id
        union all select count(*) || ' INTERVENANT_DOSSIER'     t, intervenant_id from INTERVENANT_DOSSIER where histo_destruction is null GROUP BY intervenant_id
        union all select count(*) || ' MODIFICATION_SERVICE_DU' t, intervenant_id from MODIFICATION_SERVICE_DU where histo_destruction is null GROUP BY intervenant_id
        union all select count(*) || ' PIECE_JOINTE'            t, intervenant_id from PIECE_JOINTE where histo_destruction is null GROUP BY intervenant_id
        union all select count(*) || ' SERVICE'                 t, intervenant_id from SERVICE where histo_destruction is null GROUP BY intervenant_id
        union all select count(*) || ' SERVICE_REFERENTIEL'     t, intervenant_id from SERVICE_REFERENTIEL where histo_destruction is null GROUP BY intervenant_id
        union all select count(*) || ' VALIDATION'              t, intervenant_id from VALIDATION where histo_destruction is null GROUP BY intervenant_id
        union all select count(*) || ' FORMULE_RESULTAT'        t, intervenant_id from FORMULE_RESULTAT where 1=1 GROUP BY intervenant_id
        ) cc
        GROUP BY intervenant_id)
        SELECT
          i.id, i.annee_id, i.code, i.source_code, i.statut_id, i.sync_statut, i.histo_creation, i.histo_destruction, idata.tbls
        FROM
          intervenant i
          LEFT JOIN idata ON idata.intervenant_id = i.id
        where 
            1=1 $filter
        ";

        $s = $bdd->select($sql, [], ['fetch' => \BddAdmin\Bdd::FETCH_EACH]);
        while ($i = $s->next()) {
            if (!isset($this->data[$i['ANNEE_ID']][$i['CODE']][$i['STATUT_ID']])) {
                $this->data[$i['ANNEE_ID']][$i['CODE']][$i['STATUT_ID']] = ['i' => [], 's' => [], 'd' => []];
            }
            $this->data[$i['ANNEE_ID']][$i['CODE']][$i['STATUT_ID']]['i'][] = $i;
        }


        $sql = "
        SELECT * FROM V_DIFF_INTERVENANT WHERE 1=1 $filter
        ";

        $s = $bdd->select($sql, [], ['fetch' => \BddAdmin\Bdd::FETCH_EACH]);
        while ($i = $s->next()) {
            if (!isset($this->data[$i['ANNEE_ID']][$i['CODE']][$i['STATUT_ID']])) {
                $this->data[$i['ANNEE_ID']][$i['CODE']][$i['STATUT_ID']] = ['i' => [], 's' => [], 'd' => []];
            }
            $this->data[$i['ANNEE_ID']][$i['CODE']][$i['STATUT_ID']]['d'][] = 'diff';
        }


        $sql = "SELECT 
          i.annee_id, i.code, i.statut_id, i.source_code, i.validite_debut, i.validite_fin 
        FROM
          src_intervenant i
        WHERE
          1=1 $filter
        ";
        $s   = $bdd->select($sql, [], ['fetch' => \BddAdmin\Bdd::FETCH_EACH]);
        while ($i = $s->next()) {
            if (!isset($this->data[$i['ANNEE_ID']][$i['CODE']][$i['STATUT_ID']])) {
                $this->data[$i['ANNEE_ID']][$i['CODE']][$i['STATUT_ID']] = ['i' => [], 's' => [], 'd' => []];
            }
            $this->data[$i['ANNEE_ID']][$i['CODE']][$i['STATUT_ID']]['s'][] = $i;
        }
    }



    public function makeFncs()
    {
        /* On élimine s'il n'y a aucun diff */
        $this->fncs['Aucune différence'] = function ($annee, $code, $statut, array $intervenants, array $sources, array $diff) {
            if (empty($diff)) return true;
        };
        /* Recherche des fiches uniques des 2 côtés et avec les mêmes source_code *
        $this->fncsStatuts['Fiches uniques des 2 côtés avec mêmes sources codes'] = function ($annee, $code, array $statuts) {
            if (1 == count($statuts)) {
                $statuts = current($statuts);
                if (1 == count($statuts['i']) && 1 == count($statuts['s'])) {
                    $i = $statuts['i'][0];
                    $s = $statuts['i'][0];
                    if ($i['SOURCE_CODE'] == $s['SOURCE_CODE']) {
                        return true;  // pas de problème : cas le + simple + 1 statut et tout matche
                    }
                }
            }
        };

        /* Ca matche au niveau d'un seul statut *
        $this->fncs['Fiches avec des source_code égaux'] = function ($annee, $code, $statut, array $intervenants, array $sources, array $diff) {

            if (1 == count($intervenants) && 1 == count($sources)) {
                if ($intervenants[0]['SOURCE_CODE'] == $sources[0]['SOURCE_CODE']) {

                    return true; // on a traité le pb
                }
            }
        };

        /* Recherche des fiches vides et pas dans la vue source *
        $this->fncs['Fiches avec des source_code différents'] = function ($annee, $code, $statut, array $intervenants, array $sources, array $diff) {

            if (1 == count($intervenants) && 1 == count($sources)) {
                if ($intervenants[0]['SOURCE_CODE'] != $sources[0]['SOURCE_CODE']) {
                    $sql = 'UPDATE INTERVENANT SET source_code = \'' . $sources[0]['SOURCE_CODE'] . '\' WHERE id = ' . $intervenants[0]['ID'] . ';';
                    $this->addAction($sql);

                    return true; // on a traité le pb
                }
            }
        };

        /* Recherche des fiches vides et pas dans la vue source *
        $this->fncs['Fiches vides sans aucune source'] = function ($annee, $code, $statut, array $intervenants, array $sources, array $diff) {
            if (1 == count($intervenants) && 0 == count($sources)) {
                $i = $intervenants[0];
                if (null === $i['TBLS']) {
                    $this->addAction('DELETE FROM intervenant WHERE id = ' . $i['ID'] . ' AND annee_id = ' . $annee . ';');

                    return true;
                }
            }
        };

        /* Anciens codes sans nouvelle fiche en façe *
        $this->fncs[] = function ($annee, $code, $statut, array $intervenants, array $sources, array $diff) {

            if (1 == count($intervenants) && 0 == count($sources)) {
                $c = $intervenants[0]['SOURCE_CODE'];
                $c = str_replace('-', '', $c);
                if ((string)(int)$c === $c) {
                    return true; // ancien code
                }
            }
        };

        /**/
    }



    public function exec()
    {
        foreach ($this->fncsStatuts as $currentFnc => $fnc) {
            $this->cFnc = $currentFnc;
            foreach ($this->data as $annee => $dataa) {
                $this->cAnnee = $annee;
                foreach ($dataa as $code => $ds) {
                    $this->cCode = $code;
                    $res         = $fnc($annee, $code, $ds);
                    if (true === $res) {
                        unset($this->data[$annee][$code]);
                        if (empty($this->data[$annee])) {
                            unset($this->data[$annee]);
                        }
                    }
                }
            }
        }

        foreach ($this->fncs as $currentFnc => $fnc) {
            $this->cFnc = $currentFnc;
            foreach ($this->data as $annee => $dataa) {
                $this->cAnnee = $annee;
                foreach ($dataa as $code => $ds) {
                    $this->cCode = $code;
                    foreach ($ds as $statut => $dsi) {
                        $res = $fnc($annee, $code, $statut, $dsi['i'], $dsi['s'], $dsi['d']);
                        if (true === $res) {
                            unset($this->data[$annee][$code][$statut]);
                            if (empty($this->data[$annee][$code])) {
                                unset($this->data[$annee][$code]);
                            }
                            if (empty($this->data[$annee])) {
                                unset($this->data[$annee]);
                            }
                        }
                    }
                }
            }
        }
    }



    public function addAction(string $sql)
    {
        if (!isset($this->actions[$this->cFnc])) {
            $this->actions[$this->cFnc] = [];
        }
        $this->actions[$this->cFnc][] = $sql;
    }



    public function display()
    {
        foreach ($this->data as $annee => $dataa) {
            foreach ($dataa as $code => $datai) {
                echo '<h2>Intervenant Code ' . $code . ', Année ' . $annee . '</h2>';
                echo '<table class="table table-bordered table-condensed table-extra-condensed table-hover">';
                echo "<tr><th>Statut</th><th>Fiches OSE</th><th>Fiches Sources</th></tr>";
                foreach ($datai as $statut => $di) {
                    echo "<tr><th>" . $this->statuts[$statut] . "</th><th>";
                    foreach ($di['i'] as $dii) {
                        unset($dii['CODE']);
                        unset($dii['STATUT_ID']);
                        unset($dii['ANNEE_ID']);
                        var_dump($dii);
                    }
                    echo '</th><th>';
                    foreach ($di['s'] as $dii) {
                        unset($dii['CODE']);
                        unset($dii['STATUT_ID']);
                        unset($dii['ANNEE_ID']);
                        var_dump($dii);
                    }
                    echo '</th><th>';
                    foreach ($di['d'] as $did) {
                        /*unset($did['CODE']);
                        unset($did['STATUT_ID']);
                        unset($did['ANNEE_ID']);
                        var_dump($did);*/
                        echo $did;
                    }
                    echo '</th></tr>';
                }
                echo '</table>';
            }
        }

        echo '<pre>';
        foreach ($this->actions as $fnc => $actions) {
            echo "\n\n-- $fnc\n";
            echo implode("\n", $actions);
        }
        echo '</pre>';
    }
}





$ip = new IParser();
$ip->fetch();
$ip->makeFncs();
$ip->exec();
$ip->display();
 No newline at end of file
//$sc = $container->get(\ExportRh\Connecteur\Siham\SihamConnecteur::class);
//$sc->test();
 No newline at end of file
+2 −1
Original line number Diff line number Diff line
@@ -19,7 +19,8 @@
        "unicaen/import"         : "3.1.5",
        "unicaen/tbl"            : "4.2",
        "unicaen/open-document"  : "3.0.2",
        "ocramius/proxy-manager" : "2.2.3"
        "ocramius/proxy-manager" : "2.2.3",
        "unicaen/siham"          : "^1.0"
    },
    "require-dev" : {
        "zendframework/zend-test"           : "3.3.0",
+34 −1
Original line number Diff line number Diff line
@@ -4,7 +4,7 @@
        "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
        "This file is @generated automatically"
    ],
    "content-hash": "d4d7f73605fcc0171019b55994d8d94c",
    "content-hash": "18f8830a24bceaafb795349271d75ec5",
    "packages": [
        {
            "name": "beberlei/assert",
@@ -2892,6 +2892,39 @@
            "description": "Bibliothèque utile lorsqu'on utilise un base de données Oracle",
            "time": "2020-03-05T15:42:28+00:00"
        },
        {
            "name": "unicaen/siham",
            "version": "1.4",
            "source": {
                "type": "git",
                "url": "https://git.unicaen.fr/lib/unicaen/siham.git",
                "reference": "ca056ea766128de913435f2920c43f9e5fea2e23"
            },
            "require": {
                "zendframework/zend-mail": "^2.10",
                "zendframework/zend-mime": "^2.7"
            },
            "require-dev": {
                "phpunit/phpunit": "^5.6"
            },
            "type": "library",
            "autoload": {
                "psr-0": {
                    "UnicaenSiham": "src/"
                },
                "classmap": [
                    "./Module.php"
                ]
            },
            "authors": [
                {
                    "name": "Antony Le Courtes",
                    "email": "antony.lecourtes@unicaen.fr"
                }
            ],
            "description": "PHP library for SIHAM webservices",
            "time": "2021-10-28T13:19:26+00:00"
        },
        {
            "name": "unicaen/tbl",
            "version": "4.1",
+7 −0
Original line number Diff line number Diff line
@@ -257,6 +257,13 @@ return [
        'dir'      => __DIR__ . '/data/fichiers',
    ],

    /* Export RH */
    'export-rh' => [
        //définition du connecteur SI RH à utiliser pour le module export RH de OSE
        'actif'      => true,
        'connecteur' => 'siham',
    ],


    /* Base de données Actul+ */
    'actul'    => [
+2 −1
Original line number Diff line number Diff line
@@ -95,7 +95,6 @@ class AppConfig
            'Zend\Router',
            'Zend\Session',
            'Zend\Validator',

            'DoctrineModule',
            'DoctrineORMModule',
            'ZfcUser',
@@ -103,7 +102,9 @@ class AppConfig
            'UnicaenAuth',
            'UnicaenImport',
            'UnicaenTbl',
            'UnicaenSiham',
            'Application',
            'ExportRh',
        ];

        if (!self::inConsole()) {
Loading