Commit 782a8507 authored by Laurent Lecluse's avatar Laurent Lecluse
Browse files

Possibilité de basculer une fiche de service vers l'IHM de test de la formule

parent 92efc18e
Loading
Loading
Loading
Loading
+6 −30
Original line number Diff line number Diff line
@@ -8,37 +8,13 @@
 * @var $viewFile   string
 */

$sql = "
SELECT
  w.annee_id,
  w.intervenant_id,
  si.source_code statut_intervenant,
  s.libelle_court structure,
  w.etape_code,
  w.atteignable,
  w.objectif,
  w.realisation
FROM
  tbl_workflow w
  JOIN wf_etape e ON e.id = w.etape_id
  JOIN statut_intervenant si ON si.id = w.statut_intervenant_id
  LEFT JOIN structure s ON s.id = w.structure_id
ORDER BY
  w.intervenant_id,
  e.ordre
";
$intervenant = $container->get(\Application\Service\IntervenantService::class)->get(164270);

$tvh = $container->get(\Application\Service\TypeVolumeHoraireService::class)->getPrevu();
$evh = $container->get(\Application\Service\EtatVolumeHoraireService::class)->getSaisi();

/** @var $em \Doctrine\ORM\EntityManager */
$em = $container->get(\Application\Constants::BDD);
/* @var $ftis \Application\Service\FormuleTestIntervenantService */
$ftis = $container->get(\Application\Service\FormuleTestIntervenantService::class);

$ids      = $em->getConnection()->query($sql);
$feuilles = [];

foreach ($ids as $id) {
    $intervenant = (int)$id['INTERVENANT_ID'];
    unset($id['INTERVENANT_ID']);
    $feuilles[$intervenant][] = $id;
}

var_dump($feuilles);
 No newline at end of file
$ftis->creerDepuisIntervenant($intervenant, $tvh, $evh);
 No newline at end of file
+21 −6
Original line number Diff line number Diff line
@@ -75,6 +75,21 @@ return [
                                ],
                                'may_terminate' => true,
                            ],
                            'creer-from-reel' => [
                                'type'          => 'Segment',
                                'options'       => [
                                    'route'       => '/creer-from-reel/:intervenant/:typeVolumeHoraire/:etatVolumeHoraire',
                                    'constraints' => [
                                        'typeVolumeHoraire' => '[0-9]*',
                                        'etatVolumeHoraire' => '[0-9]*',
                                    ],
                                    'defaults'    => [
                                        'action' => 'test-creer-from-reel',
                                    ],
                                ],
                                'may_terminate' => true,
                            ],

                        ],
                    ],
                ],
@@ -124,7 +139,7 @@ return [
            PrivilegeController::class => [
                [
                    'controller' => 'Application\Controller\Formule',
                    'action'     => ['test', 'test-saisir', 'test-enregistrement', 'test-supprimer'],
                    'action'     => ['test', 'test-saisir', 'test-enregistrement', 'test-supprimer', 'test-creer-from-reel'],
                    'privileges' => [Privileges::FORMULE_TESTS],
                ],
            ],
+15 −1
Original line number Diff line number Diff line
@@ -27,7 +27,6 @@ class FormuleController extends AbstractController
    use ParametresServiceAwareTrait;



    public function testAction()
    {
        $fti = $this->getServiceFormuleTestIntervenant()->getList();
@@ -147,6 +146,21 @@ class FormuleController extends AbstractController



    public function testCreerFromReelAction()
    {
        $intervenant       = $this->getEvent()->getParam('intervenant');
        $typeVolumeHoraire = $this->getEvent()->getParam('typeVolumeHoraire');
        $etatVolumeHoraire = $this->getEvent()->getParam('etatVolumeHoraire');

        $formuleTestIntervenant = $this->getServiceFormuleTestIntervenant()->creerDepuisIntervenant($intervenant, $typeVolumeHoraire, $etatVolumeHoraire);

        $url = $this->url()->fromRoute('formule-calcul/test/saisir', ['formuleTestIntervenant' => $formuleTestIntervenant->getId()]);

        return $this->redirect()->toUrl($url);
    }



    public function calculerToutAction()
    {
        $this->em()->getConnection()->exec('BEGIN OSE_FORMULE.CALCULER_TOUT; END;');
+18 −1
Original line number Diff line number Diff line
@@ -3,6 +3,8 @@
namespace Application\Service;

use Application\Entity\Db\Formule;
use Application\Service\Traits\ParametresServiceAwareTrait;


/**
 * Description of FormuleService
@@ -16,6 +18,8 @@ use Application\Entity\Db\Formule;
 */
class FormuleService extends AbstractEntityService
{
    use ParametresServiceAwareTrait;


    /**
     * retourne la classe des entités
@@ -35,8 +39,21 @@ class FormuleService extends AbstractEntityService
     *
     * @return string
     */
    public function getAlias(){
    public function getAlias()
    {
        return 'formule';
    }



    /**
     * @return Formule
     */
    public function getCurrent(): Formule
    {
        $formuleId = $this->getServiceParametres()->get('formule');

        return $this->get($formuleId);
    }

}
 No newline at end of file
+153 −2
Original line number Diff line number Diff line
@@ -2,7 +2,14 @@

namespace Application\Service;

use Application\Entity\Db\EtatVolumeHoraire;
use Application\Entity\Db\FormuleTestIntervenant;
use Application\Entity\Db\FormuleTestStructure;
use Application\Entity\Db\FormuleTestVolumeHoraire;
use Application\Entity\Db\Intervenant;
use Application\Entity\Db\TypeVolumeHoraire;
use Application\Service\Traits\FormuleServiceAwareTrait;


/**
 * Description of FormuleTestIntervenantService
@@ -16,6 +23,9 @@ use Application\Entity\Db\FormuleTestIntervenant;
 */
class FormuleTestIntervenantService extends AbstractEntityService
{
    use FormuleServiceAwareTrait;
    use FormuleServiceAwareTrait;


    /**
     * retourne la classe des entités
@@ -77,13 +87,154 @@ class FormuleTestIntervenantService extends AbstractEntityService



    public function creerDepuisIntervenant(Intervenant $intervenant, TypeVolumeHoraire $typeVolumeHoraire, EtatVolumeHoraire $etatVolumeHoraire): FormuleTestIntervenant
    {
        $conn = $this->getEntityManager()->getConnection();

        $formule            = $this->getServiceFormule()->getCurrent();
        $intervenantQuery   = trim($conn->fetchColumn('SELECT ' . $formule->getPackageName() . '.INTERVENANT_QUERY Q FROM DUAL', [], 0));
        $volumeHoraireQuery = trim($conn->fetchColumn('SELECT ' . $formule->getPackageName() . '.VOLUME_HORAIRE_QUERY Q FROM DUAL', [], 0));

        $sql = "BEGIN ose_formule.intervenant.id := " . $intervenant->getId() . "; END;";
        $conn->exec($sql);

        $params = ['intervenant' => $intervenant->getId()];

        $idata                       = $conn->fetchAll('SELECT * FROM (' . $intervenantQuery . ') q WHERE intervenant_id = :intervenant', $params)[0];
        $params['typeVolumeHoraire'] = $typeVolumeHoraire->getId();
        $params['etatVolumeHoraire'] = $etatVolumeHoraire->getId();
        $vhdata                      = $conn->fetchAll('SELECT * FROM (' . $volumeHoraireQuery . ') q WHERE intervenant_id = :intervenant AND type_volume_horaire_id = :typeVolumeHoraire AND etat_volume_horaire_id >= :etatVolumeHoraire', $params);

        $fti = new FormuleTestIntervenant();
        $fti->setLibelle((string)$intervenant);
        $fti->setFormule($formule);
        $fti->setAnnee($intervenant->getAnnee());
        $fti->setTypeIntervenant($intervenant->getStatut()->getTypeIntervenant());
        $fti->setTypeVolumeHoraire($typeVolumeHoraire);
        $fti->setEtatVolumeHoraire($etatVolumeHoraire);
        $fti->setHeuresServiceStatutaire((float)$idata['HEURES_SERVICE_STATUTAIRE']);
        $fti->setHeuresServiceModifie((float)$idata['HEURES_SERVICE_MODIFIE']);
        $fti->setDepassementServiceDuSansHC($idata['DEPASSEMENT_SERVICE_DU_SANS_HC'] == '1');
        $fti->setParam1($idata['PARAM_1']);
        $fti->setParam2($idata['PARAM_2']);
        $fti->setParam3($idata['PARAM_3']);
        $fti->setParam4($idata['PARAM_4']);
        $fti->setParam5($idata['PARAM_5']);
        $fti->setStructureCode($idata['STRUCTURE_CODE']);

        /* Réduction des types d'intervention de la fiche à CP/TD/TP/AUTRE */
        $typesIntervention = [
            'CM' => [1.5, 1.5],
            'TD' => [1, 1],
            'TP' => [1, 2 / 3],
        ];
        $nbAutres          = 0;
        foreach ($vhdata as $vhd) {
            if ($vhd['TYPE_INTERVENTION_CODE']) {
                $typesIntervention[$vhd['TYPE_INTERVENTION_CODE']] = [
                    (float)$vhd['TAUX_SERVICE_DU'],
                    (float)$vhd['TAUX_SERVICE_COMPL'],
                ];
            }
        }
        foreach ($typesIntervention as $tic => $tit) {
            if (!in_array($tic, ['CM', 'TD', 'TP'])) {
                $nbAutres++;
            } else {
                $typesIntervention[$tic][2] = $tic;
            }
        }
        if ($nbAutres == 1) {
            foreach ($typesIntervention as $tic => $tit) {
                if (!in_array($tic, ['CM', 'TD', 'TP'])) {
                    $typesIntervention[$tic][2] = 'AUTRE';
                    $nbAutres--;
                }
            }
        } else {
            if ($nbAutres > 1) {
                foreach ($typesIntervention as $tic => $tit) {
                    if (!in_array($tic, ['CM', 'TD', 'TP'])) {
                        if ($tit[0] == $typesIntervention['CM'][0] && $tit[1] == $typesIntervention['CM'][1]) {
                            $typesIntervention[$tic][2] = 'CM';
                            $nbAutres--;
                        }
                        if ($tit[0] == $typesIntervention['TD'][0] && $tit[1] == $typesIntervention['TD'][1]) {
                            $typesIntervention[$tic][2] = 'TD';
                            $nbAutres--;
                        }
                        if ($tit[0] == $typesIntervention['TP'][0] && $tit[1] == $typesIntervention['TP'][1]) {
                            $typesIntervention[$tic][2] = 'TP';
                            $nbAutres--;
                        }
                    }
                }
            }
        }
        if ($nbAutres == 1) {
            foreach ($typesIntervention as $tic => $tit) {
                if (!isset($tit[2])) {
                    $typesIntervention[$tic][2] = 'AUTRE';
                }
            }
        }

        if ($nbAutres > 1) {
            throw new \Exception('La fiche de service de cet intervenant ne peut pas être transformée en test de formule : elle comporte de trop nombreux types d\'intervention différents des CM/TP/TP');
        }

        /* On applique les taux au test de formule */
        foreach ($typesIntervention as $tic => $tit) {
            switch ($tit[2]) {
                case 'CM':
                    $fti->setTauxCmServiceDu($tit[0]);
                    $fti->setTauxCmServiceCompl($tit[1]);
                break;
                case 'TP':
                    $fti->setTauxTpServiceDu($tit[0]);
                    $fti->setTauxTpServiceCompl($tit[1]);
                break;
                case 'AUTRE':
                    $fti->setTauxAutreServiceDu($tit[0]);
                    $fti->setTauxAutreServiceCompl($tit[1]);
                break;
            }
        }

        foreach ($vhdata as $vh) {
            $ftvh = new FormuleTestVolumeHoraire();
            $ftvh->setIntervenantTest($fti);
            $ftvh->setReferentiel($vh['VOLUME_HORAIRE_REF_ID'] != null);
            $ftvh->setServiceStatutaire($vh['SERVICE_STATUTAIRE'] == '1');
            $ftvh->setTypeInterventionCode($vh['TYPE_INTERVENTION_CODE']);
            $ftvh->setStructureCode($vh['STRUCTURE_CODE']);
            $ftvh->setTauxFi((float)$vh['TAUX_FI']);
            $ftvh->setTauxFa((float)$vh['TAUX_FA']);
            $ftvh->setTauxFc((float)$vh['TAUX_FC']);
            $ftvh->setPonderationServiceDu((float)$vh['PONDERATION_SERVICE_DU']);
            $ftvh->setPonderationServiceCompl((float)$vh['PONDERATION_SERVICE_COMPL']);
            $ftvh->setParam1($vh['PARAM_1']);
            $ftvh->setParam2($vh['PARAM_2']);
            $ftvh->setParam3($vh['PARAM_3']);
            $ftvh->setParam4($vh['PARAM_4']);
            $ftvh->setParam5($vh['PARAM_5']);
            $ftvh->setHeures((float)$vh['HEURES']);
            $fti->addVolumeHoraireTest($ftvh);
        }
        $this->save($fti);

        return $fti;
    }



    /**
     * Sauvegarde une entité
     *
     * @param FormuleTestIntervenant $entity
     *
     * @throws \RuntimeException
     * @return mixed
     * @throws \RuntimeException
     */
    public function save($entity)
    {
Loading