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

Correction de l'IHM d'admin des TPJ

parent 098bdbea
Loading
Loading
Loading
Loading
+18 −14
Original line number Diff line number Diff line
@@ -11,6 +11,7 @@ use Application\Entity\Db\TypePieceJointeStatut;
use Application\Form\PieceJointe\Traits\ModifierTypePieceJointeStatutFormAwareTrait;
use Application\Service\Traits\IntervenantServiceAwareTrait;
use Application\Service\Traits\PieceJointeServiceAwareTrait;
use Intervenant\Entity\Db\Statut;
use Intervenant\Service\StatutServiceAwareTrait;
use Application\Service\Traits\TypePieceJointeServiceAwareTrait;
use Application\Service\Traits\TypePieceJointeStatutServiceAwareTrait;
@@ -339,10 +340,13 @@ class PieceJointeController extends AbstractController

    public function typePieceJointeStatutAction()
    {
        $this->em()->getFilters()->enable('historique')->init([
            \Application\Entity\Db\TypePieceJointe::class,
            \Intervenant\Entity\Db\Statut::class,
            \Application\Entity\Db\TypePieceJointeStatut::class,
        $this->em()->getFilters()->enable('historique')->init(entity: [
            TypePieceJointe::class,
            Statut::class,
            TypePieceJointeStatut::class,
        ]);
        $this->em()->getFilters()->enable('annee')->init([
            Statut::class,
        ]);

        $anneeId = $this->getServiceContext()->getAnnee()->getId();
@@ -356,17 +360,18 @@ class PieceJointeController extends AbstractController

        $dql = "
        SELECT
          tpjs, adeb, afin
          tpjs, tpj, si
        FROM
          " . \Application\Entity\Db\TypePieceJointeStatut::class . " tpjs
          LEFT JOIN tpjs.anneeDebut adeb
          LEFT JOIN tpjs.anneeFin afin
          " . TypePieceJointeStatut::class . " tpjs
          JOIN tpjs.typePieceJointe tpj
          JOIN tpjs.statut si
        WHERE
          COALESCE($anneeId,$anneeId) BETWEEN COALESCE(adeb.id,$anneeId) AND COALESCE(afin.id,$anneeId)
        "; // COALESCE($anneeId,$anneeId) bizarre mais c'est pour contourner un bug de doctrine!!!!!!
          tpjs.annee = :annee
        ";

        /* @var $tpjss TypePieceJointeStatut[] */
        $tpjss                     = $this->em()->createQuery($dql)->getResult();
        $query                     = $this->em()->createQuery($dql)->setParameters(['annee' => $this->getServiceContext()->getAnnee()->getId()]);
        $tpjss                     = $query->getResult();
        $typesPiecesJointesStatuts = [];
        foreach ($tpjss as $tpjs) {
            $tpjID = $tpjs->getTypePieceJointe()->getId();
@@ -404,7 +409,7 @@ class PieceJointeController extends AbstractController
        /* @var $typePieceJointe TypePieceJointe */
        $typePieceJointe = $this->getEvent()->getParam('typePieceJointe');

        $form = $this->getFormTypePieceJointeSaisie();
        $form = $this->getFormPieceJointeTypePieceJointeSaisie();
        if (empty($typePieceJointe)) {
            $title           = 'Création d\'un nouveau type de pièce jointe';
            $typePieceJointe = $this->getServiceTypePieceJointe()->newEntity();
@@ -424,7 +429,7 @@ class PieceJointeController extends AbstractController
        /* @var $tpjs TypePieceJointeStatut */
        $tpjs = $this->getEvent()->getParam('typePieceJointeStatut'); // $tpjs1 pour existence sur supprimer

        $form = $this->getFormModifierTypePieceJointeStatut();
        $form = $this->getFormPieceJointeModifierTypePieceJointeStatut();
        if (empty($tpjs)) {
            $title           = 'Nouveau paramètre de gestion de pièce justificative';
            $tpjs            = $this->getServiceTypePieceJointeStatut()->newEntity();
@@ -437,7 +442,6 @@ class PieceJointeController extends AbstractController
            $typePieceJointe = $tpjs->getTypePieceJointe();
            $statut          = $tpjs->getStatut();
        }
        $form->buildAnnees($tpjs);
        $form->bindRequestSave($tpjs, $this->getRequest(), $this->getServiceTypePieceJointeStatut());

        return compact('form', 'title', 'typePieceJointe', 'statut');
+1 −1
Original line number Diff line number Diff line
@@ -2,7 +2,7 @@
<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
  <entity name="Application\Entity\Db\TypePieceJointeStatut" table="TYPE_PIECE_JOINTE_STATUT">
    <unique-constraints>
      <unique-constraint name="type_piece_jointe_statut__un" columns="TYPE_PIECE_JOINTE_ID,STATUT_ID"/>
      <unique-constraint name="type_piece_jointe_statut_un" columns="TYPE_PIECE_JOINTE_ID,STATUT_ID,HISTO_DESTRUCTION"/>
    </unique-constraints>
    <id name="id" type="integer" column="ID">
      <generator strategy="SEQUENCE"/>
+0 −2
Original line number Diff line number Diff line
@@ -168,8 +168,6 @@ class TypePieceJointeStatut implements ParametreEntityInterface
        if ($this->getSeuilHetd()) $t[] = 'À partir de ' . $this->getSeuilHetd() . ' heures';
        if ($this->getFc()) $t[] = 'Uniquement avec des enseignements en Formation Continue';
        if ($this->getChangementRIB()) $t[] = 'Uniquement si le RIB a changé';
        if ($this->getAnneeDebut()) $t[] = 'Actif à partir de ' . $this->getAnneeDebut();
        if ($this->getAnneeFin()) $t[] = 'Actif jusqu\'à' . $this->getAnneeFin();
        if ($this->getDureeVie()) $t[] = 'Redemander la pièce tous les ' . $this->getDureeVie();

        return implode("\n", $t);
+5 −115
Original line number Diff line number Diff line
@@ -43,127 +43,17 @@ class TypePieceJointeStatutService extends AbstractEntityService


    /**
     * Retourne la liste des enregistrements correspondant aux statut intervenant spécifié.
     *
     * @param Statut            $statut
     * @param QueryBuilder|null $queryBuilder
     *
     * @return QueryBuilder
     */
    public function finderByStatut(Statut $statut, QueryBuilder $qb = null, $alias = null)
    {
        [$qb, $alias] = $this->initQuery($qb, $alias);
        $qb->andWhere("$alias.statut = :statut")->setParameter('statut', $statut);

        return $qb;
    }



    /**
     * @param TypePieceJointeStatut $typePieceJointeStatut
     *
     * @return \Application\Entity\Db\Annee|null
     */
    public function derniereAnneeDebut(TypePieceJointeStatut $typePieceJointeStatut)
    {
        $id     = $typePieceJointeStatut->getId() ?: 0;
        $statut = $typePieceJointeStatut->getStatut()->getId();
        $tpj    = $typePieceJointeStatut->getTypePieceJointe()->getId();
        $annee  = $this->getServiceContext()->getAnnee()->getId();
        $params = compact('id', 'statut', 'tpj', 'annee');

        $sql = "
        SELECT 
          MAX(ANNEE_FIN_ID) ANNEE_FIN
        FROM 
          TYPE_PIECE_JOINTE_STATUT TPJS
        WHERE
          TPJS.HISTO_DESTRUCTION IS NULL
          AND TPJS.STATUT_ID = :statut
          AND TPJS.TYPE_PIECE_JOINTE_ID = :tpj
          AND TPJS.ID <> :id
          AND TPJS.ANNEE_FIN_ID IS NOT NULL
          AND TPJS.ANNEE_FIN_ID < :annee
        ";
        $res = $this->getEntityManager()->getConnection()->executeQuery($sql, $params)->fetch();
        if ($res && (int)$res['ANNEE_FIN'] !== 0) {
            return $this->getServiceAnnee()->get((int)$res['ANNEE_FIN']);
        } else {
            return null;
        }
    }



    /**
     * @param TypePieceJointeStatut $typePieceJointeStatut
     *
     * @return \Application\Entity\Db\Annee|null
     */
    public function premiereAnneeFin(TypePieceJointeStatut $typePieceJointeStatut)
    {
        $id     = $typePieceJointeStatut->getId() ?: 0;
        $statut = $typePieceJointeStatut->getStatut()->getId();
        $tpj    = $typePieceJointeStatut->getTypePieceJointe()->getId();
        $annee  = $this->getServiceContext()->getAnnee()->getId();
        $params = compact('id', 'statut', 'tpj', 'annee');

        $sql = "
        SELECT 
          MAX(ANNEE_DEBUT_ID) ANNEE_DEBUT
        FROM 
          TYPE_PIECE_JOINTE_STATUT TPJS
        WHERE
          TPJS.HISTO_DESTRUCTION IS NULL
          AND TPJS.STATUT_ID = :statut
          AND TPJS.TYPE_PIECE_JOINTE_ID = :tpj
          AND TPJS.ID <> :id
          AND TPJS.ANNEE_DEBUT_ID IS NOT NULL
          AND TPJS.ANNEE_DEBUT_ID > :annee
        ";
        $res = $this->getEntityManager()->getConnection()->executeQuery($sql, $params)->fetch();
        if ($res && (int)$res['ANNEE_DEBUT'] !== 0) {
            return $this->getServiceAnnee()->get((int)$res['ANNEE_DEBUT']);
        } else {
            return null;
        }
    }



    /**
     * @param TypePieceJointeStatut $entity
     *
     * @return TypePieceJointeStatut
     */
    public function save($entity)
    {
        $ddeb = $entity->getAnneeDebut() ? $entity->getAnneeDebut()->getId() : 0;
        $dfin = $entity->getAnneeFin() ? $entity->getAnneeFin()->getId() : 99999;

        if ($dfin < $ddeb) {
            throw new \Exception('L\'année de fin ne peut être antérieure à l\'année de début');
        }

        return parent::save($entity);
    }



    /**
     * Retourne la liste des enregistrements.
     *
     * @param QueryBuilder|null $queryBuilder
     * @param QueryBuilder|null $qb
     * @param string|null       $alias
     *
     * @return TypePieceJointeStatut[]
     */
    public function getList(QueryBuilder $qb = null, $alias = null)
    public function orderBy(QueryBuilder $qb = null, $alias = null)
    {
        [$qb, $alias] = $this->initQuery($qb, $alias);

        $qb->addOrderBy("$alias.id");

        return parent::getList($qb, $alias);
        return $qb;
    }

}
 No newline at end of file