Commit 6b3b98ea authored by Laurent Lecluse's avatar Laurent Lecluse
Browse files

WIP TblPaiement

parent b3d946d4
Loading
Loading
Loading
Loading
+69 −22
Changes for module/Paiement/sql/paiement_process_heures_a_payer.sql: 69 added lines, 22 removed lines.
Original line number Diff line number Diff line
SELECT
  'e' || '-' || frs.id || '-' || th.id        key,
  CASE WHEN si.mode_enseignement_realise = 'semestriel' THEN 1 ELSE 0 END calcul_semestriel,
  vh.id                                       a_payer_id,
  i.annee_id                                  annee_id,
  frs.service_id                              service_id,
  NULL                                        service_referentiel_id,
@@ -9,8 +11,8 @@ SELECT
  i.id                                        intervenant_id,
  COALESCE( ep.structure_id, i.structure_id ) structure_id,
  th.id                                       type_heures_id,
  COALESCE(e.domaine_fonctionnel_id, ose_parametre.get_domaine_fonc_ens_ext) domaine_fonctionnel_id,
  ccep.centre_cout_id                         centre_cout_id,
  COALESCE(e.domaine_fonctionnel_id, ose_parametre.get_domaine_fonc_ens_ext) def_domaine_fonctionnel_id,
  ccep.centre_cout_id                         def_centre_cout_id,
  COALESCE(ep.taux_remu_id, si.taux_remu_id, ose_parametre.get_taux_remu) taux_remu_id,
  1                                           taux_conges_payes,
  CASE th.code
@@ -18,16 +20,23 @@ SELECT
    WHEN 'fa' THEN frs.heures_compl_fa
    WHEN 'fc' THEN frs.heures_compl_fc
    WHEN 'fc_majorees' THEN frs.heures_compl_fc_majorees
  END                                         service_heures,
  END                                         heures,
  CASE th.code
    WHEN 'fi' THEN frvh.heures_compl_fi
    WHEN 'fa' THEN frvh.heures_compl_fa
    WHEN 'fc' THEN frvh.heures_compl_fc
    WHEN 'fc_majorees' THEN frvh.heures_compl_fc_majorees
  END                                         heures,
  vh.horaire_debut                            horaire_debut,
  vh.horaire_fin                              horaire_fin,
  vh.periode_id                               periode_id
  END                                         lap_heures,
  p.code                                      periode_ens_code,
  COALESCE(vh.horaire_debut, add_months(a.date_debut, p.ecart_mois)) horaire_debut,
  COALESCE(vh.horaire_fin, add_months(a.date_debut, p.ecart_mois + 5)) horaire_fin,
  
  mep.id                                      mise_en_paiement_id,
  mep.date_mise_en_paiement                   date_mise_en_paiement,
  mep.periode_paiement_id                     periode_paiement_id,
  mep.centre_cout_id                          mep_centre_cout_id,
  mep.heures                                  mep_heures,
  mep.domaine_fonctionnel_id                  mep_domaine_fonctionnel_id
FROM
            formule_resultat_service        frs
       JOIN formule_resultat_vh            frvh ON frvh.formule_resultat_id = frs.formule_resultat_id
@@ -41,7 +50,9 @@ FROM
                                               AND fr.type_volume_horaire_id = tvh.id
                                               AND fr.etat_volume_horaire_id = evh.id

       JOIN periode                           p ON p.id = vh.periode_id
       JOIN intervenant                       i ON i.id = fr.intervenant_id
       JOIN annee                             a ON a.id = i.annee_id
       JOIN statut                           si ON si.id = i.statut_id
       JOIN service                           s ON s.id = frs.service_id
  LEFT JOIN element_pedagogique              ep ON ep.id = s.element_pedagogique_id
@@ -49,6 +60,10 @@ FROM
  LEFT JOIN centre_cout_ep                 ccep ON ccep.histo_destruction IS NULL
                                               AND ccep.element_pedagogique_id = ep.id
                                               AND ccep.type_heures_id = th.id
  
  LEFT JOIN mise_en_paiement                mep ON mep.histo_destruction IS NULL
                                               AND mep.formule_res_service_id = frs.id
                                               AND mep.type_heures_id = th.id
WHERE
   CASE th.code
    WHEN 'fi' THEN frvh.heures_compl_fi
@@ -65,6 +80,8 @@ UNION ALL

SELECT
  'r' || '-' || frsr.id || '-' || th.id       key,
  1                                           calcul_semestriel,
  sr.id                                       a_payer_id,
  i.annee_id                                  annee_id,
  NULL                                        service_id,
  frsr.service_referentiel_id                 service_referentiel_id,
@@ -74,18 +91,24 @@ SELECT
  i.id                                        intervenant_id,
  sr.structure_id                             structure_id,
  th.id                                       type_heures_id,
  fr.domaine_fonctionnel_id                   domaine_fonctionnel_id,
  NULL                                        centre_cout_id,
  fr.domaine_fonctionnel_id                   def_domaine_fonctionnel_id,
  NULL                                        def_centre_cout_id,
  COALESCE(si.taux_remu_id, ose_parametre.get_taux_remu) taux_remu_id,
  1                                           taux_conges_payes,
  NULL                                        service_heures,
  frsr.heures_compl_referentiel               heures,
  NULL                                        horaire_debut,
  NULL                                        horaire_fin,
  NULL                                        periode_id
  NULL                                        heures,
  frsr.heures_compl_referentiel               lap_heures,
  NULL                                        periode_ens_code,
  a.date_debut                                horaire_debut,
  a.date_fin                                  horaire_fin,
  
  mep.id                                      mise_en_paiement_id,
  mep.date_mise_en_paiement                   date_mise_en_paiement,
  mep.periode_paiement_id                     periode_paiement_id,
  mep.centre_cout_id                          mep_centre_cout_id,
  mep.heures                                  mep_heures,
  mep.domaine_fonctionnel_id                  mep_domaine_fonctionnel_id
FROM
            formule_resultat_service_ref    frsr

       JOIN type_volume_horaire             tvh ON tvh.code = 'REALISE'
       JOIN etat_volume_horaire             evh ON evh.code = 'valide'
       JOIN type_heures                      th ON th.code = 'referentiel'
@@ -94,9 +117,14 @@ FROM
                                               AND fr.etat_volume_horaire_id = evh.id

       JOIN intervenant                       i ON i.id = fr.intervenant_id
       JOIN annee                             a ON a.id = i.annee_id
       JOIN statut                           si ON si.id = i.statut_id
       JOIN service_referentiel              sr ON sr.id = frsr.service_referentiel_id
       JOIN fonction_referentiel             fr ON fr.id = sr.fonction_id
       
  LEFT JOIN mise_en_paiement                mep ON mep.histo_destruction IS NULL
                                               AND mep.formule_res_service_ref_id = frsr.id
                                               AND mep.type_heures_id = th.id
WHERE
   frsr.heures_compl_referentiel > 0
   /*@INTERVENANT_ID=i.id*/
@@ -108,6 +136,8 @@ UNION ALL

SELECT
  'm' || '-' || m.id || '-' || th.id          key,
  0                                           calcul_semestriel,
  vhm.id                                      a_payer_id,
  tm.annee_id                                 annee_id,
  NULL                                        service_id,
  NULL                                        service_referentiel_id,
@@ -117,8 +147,8 @@ SELECT
  tm.intervenant_id                           intervenant_id,
  m.structure_id                              structure_id,
  th.id                                       type_heures_id,
  NULL                                        domaine_fonctionnel_id,
  NULL                                        centre_cout_id,
  NULL                                        def_domaine_fonctionnel_id,
  NULL                                        def_centre_cout_id,
  CASE WHEN
    TO_CHAR( vhm.horaire_debut, 'HH24:MI' ) >= ose_parametre.get_horaire_nocturne -- horaire nocturne
    OR jf.id IS NOT NULL                                                          -- jour ferie
@@ -129,11 +159,18 @@ SELECT
    m.taux_remu_id
  END                                         taux_remu_id,
  ose_parametre.get_taux_conges_payes+1       taux_conges_payes,
  NULL                                        service_heures,
  vhm.heures                                  heures,
  vhm.horaire_debut                           horaire_debut,
  vhm.horaire_fin                             horaire_fin,
  NULL                                        periode_id
  NULL                                        heures,
  vhm.heures                                  lap_heures,
  NULL                                        periode_ens_code,
  COALESCE(vhm.horaire_debut,m.date_debut)    horaire_debut,
  COALESCE(vhm.horaire_fin,m.date_fin)        horaire_fin,
  
  mep.id                                      mise_en_paiement_id,
  mep.date_mise_en_paiement                   date_mise_en_paiement,
  mep.periode_paiement_id                     periode_paiement_id,
  mep.centre_cout_id                          mep_centre_cout_id,
  mep.heures                                  mep_heures,
  mep.domaine_fonctionnel_id                  mep_domaine_fonctionnel_id
FROM
            tbl_mission                   tm
       JOIN mission                        m ON m.id = tm.mission_id
@@ -143,9 +180,19 @@ FROM
  LEFT JOIN validation_vol_horaire_miss vvhm ON vvhm.volume_horaire_mission_id = vhm.id
  LEFT JOIN validation                     v ON v.id = vvhm.validation_id AND v.histo_destruction IS NULL
  LEFT JOIN jour_ferie jf                    ON TO_CHAR( jf.date_jour, 'dd/mm/YYYY' ) = TO_CHAR( vhm.horaire_debut, 'dd/mm/YYYY' )
  
  LEFT JOIN mise_en_paiement                mep ON mep.histo_destruction IS NULL
                                               AND mep.mission_id = m.id
                                               AND mep.type_heures_id = th.id
WHERE
  tm.valide = 1
  /*@ANNEE_ID=tm.annee_id*/
  /*@INTERVENANT_ID=tm.intervenant_id*/
  /*@MISSION_ID=tm.mission_id*/
  AND (vhm.auto_validation = 1 OR v.id IS NOT NULL)
  
ORDER BY
  intervenant_id,
  horaire_debut,
  a_payer_id,
  mise_en_paiement_id
 No newline at end of file
+69 −691

File changed.

Preview size limit exceeded, changes collapsed.

+78
Changes for module/Paiement/src/Tbl/Process/Sub/Arrondisseur.php: 78 added lines, 0 removed lines.
Original line number Diff line number Diff line
<?php

namespace Paiement\Tbl\Process\Sub;

class Arrondisseur
{

    private array $possibilites = [
        -1 => [
            0 => 1,
            1 => 9,
            2 => 8,
            3 => 7,
            4 => 3,
            5 => 2,
            6 => 8,
            7 => 6,
            8 => 5,
            9 => 4,
        ],
        1  => [
            0 => 1,
            1 => 4,
            2 => 5,
            3 => 6,
            4 => 8,
            5 => 2,
            6 => 3,
            7 => 7,
            8 => 8,
            9 => 9,
        ]
    ];



    public function arrondir(ServiceAPayer $sap)
    {
        if ($sap->heures === null) {
            return;
        }

        $vhHeures = 0;
        foreach ($sap->lignesAPayer as $id => $lap) {
            $vhHeures = $vhHeures + $lap->heures;
        }

        $diff = $sap->heures - $vhHeures;

        if ($diff === 0 || empty($sap->lignesAPayer)) {
            return; // rien à faire
        }

        $sens = $diff > 0 ? 1 : -1;
        $occurences = (int)abs($diff);

        $allreadyChanged = [];
        for ($occ = 0; $occ < $occurences; $occ++) {
            $selected = null;
            $maxScore = -1;
            foreach ($sap->lignesAPayer as $k => $lap) {
                $nbr = '00'.(string)$lap->heures;
                $cent = (int)substr($nbr, -1);
                $dec = (int)substr($nbr, -2, 1);
                $score = 100000 * $this->possibilites[$sens][$cent] + 10000 * $this->possibilites[$sens][$dec];
                if (in_array($k, $allreadyChanged)) {
                    $score = $score / 100;
                }
                if ($score > $maxScore) {
                    $maxScore = $score;
                    $selected = $k;
                }
            }
            $sap->lignesAPayer[$selected]->heures = (int)round($sap->lignesAPayer[$selected]->heures + $sens);
            $allreadyChanged[] = $selected;
        }
    }
}
 No newline at end of file
+31
Changes for module/Paiement/src/Tbl/Process/Sub/Consolidateur.php: 31 added lines, 0 removed lines.
Original line number Diff line number Diff line
<?php

namespace Paiement\Tbl\Process\Sub;

class Consolidateur
{

    public function consolider(ServiceAPayer $sap)
    {
        $oldLap = $sap->lignesAPayer;
        $sap->lignesAPayer = [];

        foreach ($oldLap as $l) {
            $key = $l->key;
            if (!isset($sap->lignesAPayer[$key])) {
                $lap = new LigneAPayer();
                $sap->lignesAPayer[$key] = $lap;
                $lap->tauxRemu = $l->tauxRemu;
                $lap->tauxValeur = $l->tauxValeur;
                $lap->heures = 0;
                $lap->heuresAA = 0;
                $lap->heuresAC = 0;
            }
            $heuresAA = $l->heures * $l->pourcAA;
            $sap->lignesAPayer[$key]->heures = $sap->lignesAPayer[$key]->heures + $l->heures;
            $sap->lignesAPayer[$key]->heuresAA = $sap->lignesAPayer[$key]->heuresAA + $heuresAA;
            $sap->lignesAPayer[$key]->heuresAC = $sap->lignesAPayer[$key]->heuresAC + $l->heures - $heuresAA;
        }
    }

}
 No newline at end of file
+66
Changes for module/Paiement/src/Tbl/Process/Sub/LigneAPayer.php: 66 added lines, 0 removed lines.
Original line number Diff line number Diff line
<?php

namespace Paiement\Tbl\Process\Sub;

use Paiement\Service\TauxRemuServiceAwareTrait;

class LigneAPayer
{
    public int $id;
    public string $key;
    public int $tauxRemu;
    public float $tauxValeur;
    public float $pourcAA;
    public int $heures;
    public int $heuresAA;
    public int $heuresAC;

    /** @var array|MiseEnPaiement[] */
    public array $misesEnPaiement = [];



    public function fromBdd(array $data)
    {
        $this->id = (int)$data['A_PAYER_ID'];
        $this->tauxRemu = (int)$data['TAUX_REMU_ID'];
        $this->heures = (int)round((float)$data['LAP_HEURES'] * 100);
        $this->key = $this->tauxRemu . '-' . $this->tauxValeur;
    }



    public function fromArray(array $data)
    {
        foreach ($data as $k => $v) {
            if (!in_array($k, ['misesEnPaiement'])) {
                $this->$k = $v;
            }
        }
        if (isset($data['misesEnPaiement'])) {
            foreach ($data['misesEnPaiement'] as $mid => $dmep) {
                $mep = new MiseEnPaiement();
                $mep->fromArray($dmep);
                $this->misesEnPaiement[$mid] = $mep;
            }
        }
    }



    public function toArray(): array
    {
        $vars = get_object_vars($this);

        foreach ($vars['misesEnPaiement'] as $id => $mep) {
            $vars['misesEnPaiement'][$id] = $mep->toArray();
        }

        if (empty($vars['misesEnPaiement'])){
            unset($vars['misesEnPaiement']);
        }

        return $vars;
    }

}
 No newline at end of file
Loading