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

Corrections de bugs de tri lié aux états de paiement

parent 97550fc4
Loading
Loading
Loading
Loading
−25 B (40.3 KiB)

File changed.

No diff preview for this file type.

+14 −2
Original line number Diff line number Diff line
@@ -4,9 +4,21 @@ $pourcFormatter = function($value){
    $value = (float)$value * 100;
    return number_format( $value, 2, ',', ' ').'%';
};
$curFormatter = function($value){
    if ($value == '') return '';
    $value = (float)$value;
    return number_format( $value, 2, ',', ' ').' €';
};

$document->addFormatter('hetd_pourc', $pourcFormatter);
$document->addFormatter('st_hetd_pourc', $pourcFormatter);
$document->addFormatter('t_hetd_pourc', $pourcFormatter);
$document->addFormatter('hetd_montant', $curFormatter);
$document->addFormatter('st_hetd_montant', $curFormatter);
$document->addFormatter('t_hetd_montant', $curFormatter);
$document->addFormatter('rem_fc_d714', $curFormatter);
$document->addFormatter('st_rem_fc_d714', $curFormatter);
$document->addFormatter('t_rem_fc_d714', $curFormatter);

/* Mise en relief des données à partir de la requête originale */
$variables    = [
+0 −111
Original line number Diff line number Diff line
<?php
/* Initialisation : mise en place du formatage des variables */
$pourcFormatter = function($value){
    $value = (float)$value * 100;
    return number_format( $value, 2, ',', ' ').'%';
};
$document->addFormatter('hetd_pourc', $pourcFormatter);
$document->addFormatter('st_hetd_pourc', $pourcFormatter);
$document->addFormatter('t_hetd_pourc', $pourcFormatter);

/* Mise en relief des données à partir de la requête originale */
$variables    = [
    'etat'               => 'Indéfini',
    'periode_composante' => 'Indéfinie',
    'annee'              => 'Indéfinie',
    't_hetd'             => 0,
    't_hetd_montant'     => 0,
    't_rem_fc_d714'      => 0,
    't_exercice_aa'      => 0,
    't_exercice_ac'      => 0,
    'intervenants'       => 0,
];
$intervenants = [];
foreach ($data as $d) {
    $iid = (int)$d['INTERVENANT_ID'];

    $d['HETD']         = (float)$d['HETD'];
    $d['HETD_POURC']   = (float)$d['HETD_POURC'];
    $d['HETD_MONTANT'] = (float)$d['HETD_MONTANT'];
    $d['REM_FC_D714']  = (float)$d['REM_FC_D714'];
    $d['EXERCICE_AA']  = (float)$d['EXERCICE_AA'];
    $d['EXERCICE_AC']  = (float)$d['EXERCICE_AC'];

    $etat = $d['ETAT'] == 'a-mettre-en-paiement' ? 'Demandes de mises en paiement' : 'État de paiement';

    if ($variables['etat'] == 'Indéfini') $variables['etat'] = $etat;
    if ($variables['etat'] != $etat) $variables['etat'] = 'Mises en paiement (état & demandes)';

    $pc = $d['COMPOSANTE'];
    if ($d['PERIODE']) $pc .= "\nPaye du mois de " . $d['PERIODE'];
    if ($variables['periode_composante'] == 'Indéfinie') $variables['periode_composante'] = $pc;
    if ($variables['periode_composante'] != $pc) $variables['periode_composante'] = 'Toutes composantes et périodes';

    if ($variables['annee'] == 'Indéfinie') $variables['annee'] = $d['ANNEE'];
    if ($variables['annee'] != $d['ANNEE']) $variables['annee'] = 'Toutes années';

    if (!isset($intervenants[$iid])) {
        $intervenants[$iid] = [
            'lignes'          => [],
            'st_hetd'         => 0,
            'st_hetd_pourc'   => 0,
            'st_hetd_montant' => 0,
            'st_rem_fc_d714'  => 0,
            'st_exercice_aa'  => 0,
            'st_exercice_ac'  => 0,
        ];
    }

    $intervenants[$iid]['lignes'][] = [
        'intervenant_nom'             => $d['INTERVENANT_NOM'],
        'intervenant_numero_insee'    => $d['INTERVENANT_NUMERO_INSEE'],
        'centre_cout_code'            => $d['CENTRE_COUT_CODE'],
        'domaine_fonctionnel_libelle' => $d['DOMAINE_FONCTIONNEL_LIBELLE'],
        'hetd'                        => $d['HETD'],
        'hetd_pourc'                  => $d['HETD_POURC'],
        'hetd_montant'                => $d['HETD_MONTANT'],
        'rem_fc_d714'                 => $d['REM_FC_D714'],
        'exercice_aa'                 => $d['EXERCICE_AA'],
        'exercice_ac'                 => $d['EXERCICE_AC'],
    ];

    $intervenants[$iid]['st_hetd']         += $d['HETD'];
    $intervenants[$iid]['st_hetd_pourc']   += $d['HETD_POURC'];
    $intervenants[$iid]['st_hetd_montant'] += $d['HETD_MONTANT'];
    $intervenants[$iid]['st_rem_fc_d714']  += $d['REM_FC_D714'];
    $intervenants[$iid]['st_exercice_aa']  += $d['EXERCICE_AA'];
    $intervenants[$iid]['st_exercice_ac']  += $d['EXERCICE_AC'];

    $variables['t_hetd']         += $d['HETD'];
    $variables['t_hetd_montant'] += $d['HETD_MONTANT'];
    $variables['t_rem_fc_d714']  += $d['REM_FC_D714'];
    $variables['t_exercice_aa']  += $d['EXERCICE_AA'];
    $variables['t_exercice_ac']  += $d['EXERCICE_AC'];
}
$variables['intervenants'] = count($intervenants);

/* Exploitation des données pour la publication du codument */
$publisher = $document->getPublisher();
$publisher->publishBegin();

// Récupération des sous-documents, à savoir les lignes de tableau servant de modèles
$detailTemplate = $publisher->getSubDoc($publisher->getBody(), $publisher::TABLE_ROW, 'hetd');
$totalTemplate  = $publisher->getSubDoc($publisher->getBody(), $publisher::TABLE_ROW, 'st_hetd');

// Publication des lignes
foreach ($intervenants as $intervenant) {
    foreach ($intervenant['lignes'] as $detailData) {
        $publisher->publishBefore($detailTemplate, $detailData, $totalTemplate);
    }
    $totalData = $intervenant;
    unset($totalData['lignes']);
    $publisher->publishBefore($totalTemplate, $totalData, $totalTemplate);
}

// Suppression des lignes de modèles dans le docmument
$publisher->remove($detailTemplate);
$publisher->remove($totalTemplate);

// Publication des variables au niveau du document (dernière ligne du tableau, et fin du traitement
$publisher->publishValues($publisher->getBody(), $variables);
$publisher->publishEnd();
 No newline at end of file
+189 −0
Original line number Diff line number Diff line

CREATE OR REPLACE FORCE VIEW "V_ETAT_PAIEMENT" ("ANNEE_ID", "TYPE_INTERVENANT_ID", "STRUCTURE_ID", "PERIODE_ID", "INTERVENANT_ID", "CENTRE_COUT_ID", "DOMAINE_FONCTIONNEL_ID", "ANNEE", "ETAT", "COMPOSANTE", "DATE_MISE_EN_PAIEMENT", "PERIODE", "STATUT", "INTERVENANT_CODE", "INTERVENANT_NOM", "INTERVENANT_NUMERO_INSEE", "CENTRE_COUT_CODE", "CENTRE_COUT_LIBELLE", "DOMAINE_FONCTIONNEL_CODE", "DOMAINE_FONCTIONNEL_LIBELLE", "HETD", "HETD_POURC", "HETD_MONTANT", "REM_FC_D714", "EXERCICE_AA", "EXERCICE_AA_MONTANT", "EXERCICE_AC", "EXERCICE_AC_MONTANT") AS
  SELECT
         annee_id,
         type_intervenant_id,
         structure_id,
         periode_id,
         intervenant_id,
         centre_cout_id,
         domaine_fonctionnel_id,

         annee_id || '/' || (annee_id+1) annee,
         etat,
         composante,
         date_mise_en_paiement,
         periode,
         statut,
         intervenant_code,
         intervenant_nom,
         intervenant_numero_insee,
         centre_cout_code,
         centre_cout_libelle,
         domaine_fonctionnel_code,
         domaine_fonctionnel_libelle,
         hetd,
         CASE WHEN pourc_ecart >= 0 THEN
             CASE WHEN RANK() OVER (PARTITION BY periode_id, intervenant_id, etat, structure_id ORDER BY CASE WHEN (pourc_ecart >= 0 AND pourc_diff >= 0) OR (pourc_ecart < 0 AND pourc_diff < 0) THEN pourc_diff ELSE -1 END DESC) <= (ABS(pourc_ecart) / 0.001) THEN hetd_pourc + (pourc_ecart / ABS(pourc_ecart) * 0.001) ELSE hetd_pourc END
              ELSE
             CASE WHEN RANK() OVER (PARTITION BY periode_id, intervenant_id, etat, structure_id ORDER BY CASE WHEN (pourc_ecart >= 0 AND pourc_diff >= 0) OR (pourc_ecart < 0 AND pourc_diff < 0) THEN pourc_diff ELSE -1 END) <= (ABS(pourc_ecart) / 0.001) THEN hetd_pourc + (pourc_ecart / ABS(pourc_ecart) * 0.001) ELSE hetd_pourc END
             END hetd_pourc,
         hetd_montant,
         rem_fc_d714,
         exercice_aa,
         exercice_aa_montant,
         exercice_ac,
         exercice_ac_montant
  FROM
       (
       SELECT
              dep3.*,

              1-CASE WHEN hetd > 0 THEN SUM( hetd_pourc ) OVER ( PARTITION BY periode_id, intervenant_id, etat, structure_id) ELSE 0 END pourc_ecart


       FROM (

            SELECT
                   periode_id,
                   structure_id,
                   type_intervenant_id,
                   intervenant_id,
                   annee_id,
                   centre_cout_id,
                   domaine_fonctionnel_id,
                   etat,
                   composante,
                   date_mise_en_paiement,
                   periode,
                   statut,
                   intervenant_code,
                   intervenant_nom,
                   intervenant_numero_insee,
                   centre_cout_code,
                   centre_cout_libelle,
                   domaine_fonctionnel_code,
                   domaine_fonctionnel_libelle,
                   hetd,
                   ROUND( CASE WHEN hetd > 0 THEN hetd / SUM( hetd ) OVER( PARTITION BY periode_id, intervenant_id, etat, structure_id) ELSE 0 END, 3 ) hetd_pourc,
                   ROUND( hetd * taux_horaire, 2 ) hetd_montant,
                   ROUND( fc_majorees * taux_horaire, 2 ) rem_fc_d714,
                   exercice_aa,
                   ROUND( exercice_aa * taux_horaire, 2 ) exercice_aa_montant,
                   exercice_ac,
                   ROUND( exercice_ac * taux_horaire, 2 ) exercice_ac_montant,


                   (CASE WHEN hetd > 0 THEN hetd / SUM( hetd ) OVER( PARTITION BY periode_id, intervenant_id, etat, structure_id) ELSE 0 END)
                     -
                   ROUND( CASE WHEN hetd > 0 THEN hetd / SUM( hetd ) OVER( PARTITION BY periode_id, intervenant_id, etat, structure_id) ELSE 0 END, 3 ) pourc_diff

            FROM (
                 WITH dep AS ( -- détails par état de paiement
                     SELECT
                            CASE WHEN th.code = 'fc_majorees' THEN 1 ELSE 0 END                 is_fc_majoree,
                            p.id                                                                periode_id,
                            s.id                                                                structure_id,
                            i.id                                                                intervenant_id,
                            i.annee_id                                                          annee_id,
                            cc.id                                                               centre_cout_id,
                            df.id                                                               domaine_fonctionnel_id,
                            ti.id                                                               type_intervenant_id,
                            CASE
                              WHEN mep.date_mise_en_paiement IS NULL THEN 'a-mettre-en-paiement'
                              ELSE 'mis-en-paiement'
                                END                                                                 etat,

                            TRIM(p.libelle_long || ' ' || to_char( add_months( a.date_debut, p.ecart_mois ), 'yyyy' )) periode,
                            mep.date_mise_en_paiement                                           date_mise_en_paiement,
                            s.libelle_court                                                     composante,
                            ti.libelle                                                          statut,
                            i.source_code                                                       intervenant_code,
                            i.nom_usuel || ' ' || i.prenom                                      intervenant_nom,
                            TRIM( NVL(i.numero_insee,'') || NVL(TO_CHAR(i.numero_insee_cle,'00'),'') ) intervenant_numero_insee,
                            cc.source_code                                                      centre_cout_code,
                            cc.libelle                                                          centre_cout_libelle,
                            df.source_code                                                      domaine_fonctionnel_code,
                            df.libelle                                                          domaine_fonctionnel_libelle,
                            CASE WHEN th.code = 'fc_majorees' THEN 0 ELSE mep.heures END        hetd,
                            CASE WHEN th.code = 'fc_majorees' THEN mep.heures ELSE 0 END        fc_majorees,
                            mep.heures * 4 / 10                                                 exercice_aa,
                            mep.heures * 6 / 10                                                 exercice_ac,
                         --CASE WHEN th.code = 'fc_majorees' THEN 0 ELSE mep.heures END * 4 / 10                                                 exercice_aa,
                         --CASE WHEN th.code = 'fc_majorees' THEN 0 ELSE mep.heures END * 6 / 10                                                 exercice_ac,
                            OSE_FORMULE.GET_TAUX_HORAIRE_HETD( NVL(mep.date_mise_en_paiement,SYSDATE) )      taux_horaire
                     FROM
                          v_mep_intervenant_structure  mis
                            JOIN mise_en_paiement        mep ON mep.id = mis.mise_en_paiement_id AND mep.histo_destruction IS NULL
                            JOIN type_heures              th ON  th.id = mep.type_heures_id
                            JOIN centre_cout              cc ON  cc.id = mep.centre_cout_id      -- pas d'historique pour les centres de coût, qui devront tout de même apparaitre mais en erreur
                            JOIN intervenant               i ON   i.id = mis.intervenant_id      AND i.histo_destruction IS NULL
                            JOIN annee                     a ON   a.id = i.annee_id
                            JOIN statut_intervenant       si ON  si.id = i.statut_id
                            JOIN type_intervenant         ti ON  ti.id = si.type_intervenant_id
                            JOIN structure                 s ON   s.id = mis.structure_id
                            LEFT JOIN validation           v ON   v.id = mep.validation_id       AND v.histo_destruction IS NULL
                            LEFT JOIN domaine_fonctionnel df ON  df.id = mis.domaine_fonctionnel_id
                            LEFT JOIN periode              p ON   p.id = mep.periode_paiement_id
                 )
                 SELECT
                        periode_id,
                        structure_id,
                        type_intervenant_id,
                        intervenant_id,
                        annee_id,
                        centre_cout_id,
                        domaine_fonctionnel_id,
                        etat,
                        periode,
                        composante,
                        date_mise_en_paiement,
                        statut,
                        intervenant_code,
                        intervenant_nom,
                        intervenant_numero_insee,
                        centre_cout_code,
                        centre_cout_libelle,
                        domaine_fonctionnel_code,
                        domaine_fonctionnel_libelle,
                        SUM( hetd ) hetd,
                        SUM( fc_majorees ) fc_majorees,
                        SUM( exercice_aa ) exercice_aa,
                        SUM( exercice_ac ) exercice_ac,
                        taux_horaire
                 FROM
                      dep
                 GROUP BY
                          periode_id,
                          structure_id,
                          type_intervenant_id,
                          intervenant_id,
                          annee_id,
                          centre_cout_id,
                          domaine_fonctionnel_id,
                          etat,
                          periode,
                          composante,
                          date_mise_en_paiement,
                          statut,
                          intervenant_code,
                          intervenant_nom,
                          intervenant_numero_insee,
                          centre_cout_code,
                          centre_cout_libelle,
                          domaine_fonctionnel_code,
                          domaine_fonctionnel_libelle,
                          taux_horaire,
                          is_fc_majoree
                 )
                     dep2
            )
                dep3
       )
           dep4
  ORDER BY
           annee_id,
           type_intervenant_id,
           structure_id,
           periode_id,
           intervenant_nom;
+2 −2
Original line number Diff line number Diff line
@@ -172,7 +172,7 @@ class MiseEnPaiementService extends AbstractEntityService
            $conditions['etat'] = 'etat = \'' . $e . '\'';
        }
        if ($p = $recherche->getPeriode()) {
            $conditions['periode_id'] = 'periode_paiement_id = ' . $p->getId();
            $conditions['periode_id'] = 'periode_id = ' . $p->getId();
        }
        if ($s = $recherche->getStructure()) {
            $conditions['structure_id'] = 'structure_id = ' . $s->getId();
@@ -277,7 +277,7 @@ class MiseEnPaiementService extends AbstractEntityService
            $conditions['etat'] = 'etat = \'' . $e . '\'';
        }
        if ($p = $recherche->getPeriode()) {
            $conditions['periode_id'] = 'periode_paiement_id = ' . $p->getId();
            $conditions['periode_id'] = 'periode_id = ' . $p->getId();
        }
        if ($s = $recherche->getStructure()) {
            $conditions['structure_id'] = 'structure_id = ' . $s->getId();