Commit ccc008e4 authored by Stephane Bouvry's avatar Stephane Bouvry
Browse files

Ajout d'une gestion des référents Hors-Lot dans l'écran de gestion des...

Ajout d'une gestion des référents Hors-Lot dans l'écran de gestion des déclarations + indicateur visuels
parent ff0b1bc7
Loading
Loading
Loading
Loading
+26 −2
Original line number Diff line number Diff line
@@ -2067,8 +2067,32 @@ class TimesheetController extends AbstractOscarController
        $this->getOscarUserContext()->check(Privileges::MAINTENANCE_VALIDATION_MANAGE);
        $method = $this->getHttpXMethod();

        if( $method == 'POST' ){
            return  $this->getResponseNotImplemented();
        if( $method == 'POST' && !$this->isAjax() ){
            $action = $this->params()->fromPost('action');
            switch( $action ){
                case 'addvalidator':
                    $declarer = $this->getPersonService()->getPersonById($this->params()->fromPost('person'), true);
                    $validator = $this->getPersonService()->getPersonById($this->params()->fromPost('validatorId'), true);
                    try {
                        $this->getLogger()->notice("Ajout de $validator comme validateur Hors-Lot pour $declarer");
                        $this->getPersonService()->addReferentToDeclarerHorsLot($declarer, $validator, true);
                    } catch (\Exception $e){
                        $this->getLogger()->error($e->getMessage());
                        $this->flashMessenger()->addErrorMessage("$validator n'a pas été ajouté aux déclarations : " . $e->getMessage());
                    }

                    try {
                        $this->getLogger()->notice("Ajout de $validator comme validateur Hors-Lot pour $declarer");
                        $this->getPersonService()->addReferent($validator->getId(), $declarer->getId());
                    } catch ( \Exception $e ){
                        $this->getLogger()->error($e->getMessage());
                        $this->flashMessenger()->addErrorMessage("$validator n'a pas été assigné comme validateur Hors-Lot pour $declarer : " . $e->getMessage());

                    }
                    return $this->redirect()->toRoute('timesheet/declarations');
                default:
                    return $this->getResponseBadRequest();
            }
        }

        if( $this->isAjax() ){
+27 −0
Original line number Diff line number Diff line
@@ -299,6 +299,16 @@ class PersonService implements ServiceLocatorAwareInterface, EntityManagerAwareI
        $person = $this->getPersonById($person_id, true);

        // @todo Vérifier si le référent n'est pas déjà identifié
        $verif = $this->getEntityManager()->getRepository(Referent::class)->createQueryBuilder('r')
            ->where('r.referent = :referent AND r.person = :person')
            ->setParameters([
                'referent' => $referent,
                'person' => $person
            ])->getQuery()->getResult();
        if( count($verif) > 0 ){
            throw new OscarException("$referent est déjà identifié comme référent pour $person");
        }


        $referentRec = new Referent();
        $this->getEntityManager()->persist($referentRec);
@@ -308,6 +318,23 @@ class PersonService implements ServiceLocatorAwareInterface, EntityManagerAwareI
        return true;
    }

    public function addReferentToDeclarerHorsLot(Person $declarer, Person $referent, $flush = false){
        /** @var TimesheetService $timesheetService */
        $timesheetService = $this->getServiceLocator()->get('TimesheetService');

        // Mise à jour des déclarations en attentes
        $validationPeriods = $timesheetService->getValidationHorsLotToValidateByPerson($declarer, true);

        /** @var ValidationPeriod $validationPeriod */
        foreach ($validationPeriods as $validationPeriod){
            $this->getLoggerService()->notice(sprintf("$referent est maintenant validateur administratif pour $validationPeriod"));
            $validationPeriod->addValidatorAdm($referent);
        }

        if( $flush == true && count($validationPeriods) > 0 )
            $this->getEntityManager()->flush();
    }

    /**
     * Remplace la personne référente par une autre personne.
     * @param Person $personNewReferent
+54 −7
Original line number Diff line number Diff line
@@ -135,19 +135,49 @@ class TimesheetService implements ServiceLocatorAwareInterface, EntityManagerAwa
        }
    }

    /**
     * Retourne les référents de la personnes sous la forme d'un tableau.
     * @param Person $person
     * @return array
     */
    public function getDeclarantInfos(Person $person){
        $datas = $person->toJson();
        $datas['referents'] = [];
        $referents = $this->getPersonService()->getReferentsPerson($person->getId());

        /** @var Referent $referent */
        foreach ($referents as $referent) {
            $referentDisplayName = $referent->getReferent()->getDisplayName();
            $referentId = $referent->getReferent()->getId();
            if( !array_key_exists($referentId, $datas['referents'])){
                $datas['referents'][$referentId] = [
                    'id' => $referentId,
                    'displayname' => $referentDisplayName
                ];
            }
        }
        return $datas;
    }


    public function getDatasDeclarations()
    {
        $output = [];
        $output = [
            "periods" => [],
            "declarants" => []
        ];

        // --- Récupération des déclarations
        $declarations = $this->getEntityManager()->getRepository(ValidationPeriod::class)->findAll();

        /** @var ValidationPeriod $declaration */
        foreach ($declarations as $declaration) {
            $period = sprintf('%s-%s', $declaration->getYear(), $declaration->getMonth());
            $personId = $declaration->getDeclarer()->getId();
            $dataKey = sprintf('%s_%s', $period, $personId);

            if (!array_key_exists($dataKey, $output)) {
                $output[$dataKey] = [
            if (!array_key_exists($dataKey, $output['periods'])) {
                $output['periods'][$dataKey] = [
                    'key' => $dataKey,
                    'period' => $period,
                    'person' => (string)$declaration->getDeclarer(),
@@ -160,6 +190,10 @@ class TimesheetService implements ServiceLocatorAwareInterface, EntityManagerAwa
                ];
            }

            if( !array_key_exists($personId, $output['declarants']) ){
                $output['declarants'][$personId] = $this->getDeclarantInfos($declaration->getDeclarer());
            }

            $object = $declaration->getObject();

            if ($object == ValidationPeriod::OBJECT_ACTIVITY) {
@@ -173,14 +207,14 @@ class TimesheetService implements ServiceLocatorAwareInterface, EntityManagerAwa

            if( $declaration->getObjectGroup() == ValidationPeriod::GROUP_WORKPACKAGE ){
                if( count($declaration->getValidatorsPrj()) == 0 ){
                    $output[$dataKey]['warnings'][] = _('Aucun validateur projet pour cette déclaration ')  . $label;
                    $periods[$dataKey]['warnings'][] = _('Aucun validateur projet pour cette déclaration ')  . $label;
                }
                if( count($declaration->getValidatorsSci()) == 0 ){
                    $output[$dataKey]['warnings'][] = _('Aucun validateur scientifique pour la déclaration ') . $label ;
                    $periods[$dataKey]['warnings'][] = _('Aucun validateur scientifique pour la déclaration ') . $label ;
                }
            }
            if( count($declaration->getValidatorsAdm()) == 0 ){
                $output[$dataKey]['warnings'][] = _('Aucun validateur administratif pour cette déclaration ')  . $label;
                $periods[$dataKey]['warnings'][] = _('Aucun validateur administratif pour cette déclaration ')  . $label;
            }

            $declarationDatas = $declaration->toJson();
@@ -189,8 +223,9 @@ class TimesheetService implements ServiceLocatorAwareInterface, EntityManagerAwa
            $declarationDatas['period'] = $period;
            $declarationDatas['validation'] = $declaration->getState();

            $output[$dataKey]['declarations'][] = $declarationDatas;
            $output['periods'][$dataKey]['declarations'][] = $declarationDatas;
        }

        return $output;
    }

@@ -2995,6 +3030,18 @@ class TimesheetService implements ServiceLocatorAwareInterface, EntityManagerAwa
        return $validations;
    }

    public function getValidationHorsLotToValidateByPerson( Person $person ){
        /** @var ValidationPeriodRepository $validationPeriodRepository */
        $validationPeriodRepository = $this->getEntityManager()->getRepository(ValidationPeriod::class);

        $validations = $validationPeriodRepository->getValidationPeriodsOutWPToValidate($person->getId());

        if( count($validations) == 0 )
            throw new OscarException("Aucune déclarations Hors-Lot en attente pour $person");

       return $validations;
    }

    /**
     * Retourne la liste des déclarations en fonction du validateur (référent)
     * @param Person $referent
+6 −0
Original line number Diff line number Diff line
@@ -286,6 +286,12 @@
    overflow-y: auto;
    padding-right: .5em;
  }

  .declaration-details {
    max-height: 100%;
    overflow-y: auto;
    padding-left: .5em;
  }
}


+4 −0
Original line number Diff line number Diff line
@@ -5564,6 +5564,10 @@ button.close {
    max-height: 100%;
    overflow-y: auto;
    padding-right: .5em; }
  .declarations-ui .declaration-details {
    max-height: 100%;
    overflow-y: auto;
    padding-left: .5em; }

.data-list {
  color: #999; }
Loading