<?php

namespace Modules\Ajax\Controller;

use Entity\Model\DaModel;
use Entity\Model\DaModele;
use Entity\Model\DomaineFonctionnel;
use Entity\Model\Hastutil;
use Entity\Model\Paramnum;
use Entity\Model\ProfilTva;
use Helpers\QueryBuilder\QueryBuilder;
use Modules\GlobalApplication\Repository\LicenceOxalys;
use Modules\GlobalApplication\Repository\Societe;
use Modules\Tables\MenuContextuel\CentresContextuel;
use Skeleton\Controller\Controller;
use TwigExtension\ConvertLibelleExtension;
use Modules\Ajax\Repository\Listes;
use Helpers\Pagination\Paginator;
use Helpers\Trad\Trad;
use Helpers\Outil\Sql;
use Helpers\Outil\Date;
use Entity\Model\UO;
use Entity\Model\BceFexp;
use Entity\Model\Fabricant;
use Entity\Model\Gamme;
use Entity\Model\Grpfou;
use Entity\Model\Sscptana;
use Entity\Model\Fcontfrn;
use Entity\Model\CaEntet;
use Entity\Model\BrRecep;
use Entity\Model\MotClef;
use Entity\Model\Periodes;
use Entity\Model\Messstan;
use Entity\Model\Cqualite;
use Entity\Model\Langues;
use Entity\Model\Douanes;
use Entity\Model\Suicadat;
use Entity\Model\OxalinkUser;
use Entity\Model\DomaineCompetence;
use Helpers\ChampsSupplementaire\ChampSupp;
use Helpers\Pagination\PaginatorGestion;
use Helpers\Outil\Outils;
use Modules\Ajax\Service\ListeService;
use Modules\Consultation\Repository\GestionConsultation;
use Entity\Model\AoExCentre;
use Entity\Model\Articles;
use Entity\Model\BrLigne;
use Entity\Model\Centre;
use Entity\Model\CsTypes;
use Entity\Model\DccEntet;
use Entity\Model\FoncUsr;
use Entity\Model\Paravrac;
use Entity\Model\Pays;
use Entity\Model\SousFamille;
use Entity\Model\Tiers;
use Helpers\Ariane\Ariane;
use Helpers\Outil\Roles;
use Modules\Commande\Repository\GareDeTriage;
use Modules\Fournisseur\Repository\GestFourniss;
use Modules\RechercheArticles\Repository\Recherche;
use Modules\RechercheArticles\Service\OutilRechercheService;

class ListeController extends Controller
{
    public function entityListAction(): string
    {
        $entity = $this->request->getAttribute('entity');
        $post = $this->request->getParsedBody();

        $entityGenerator = $this->getQueryBuilder($entity);

        $primaryKey = $entityGenerator->getPrimaryKey();
        $libelleKey = $entityGenerator->getLibelle();

        $listEntity = $entityGenerator->fetchAll(
            [],
            [
                'filter_' . $primaryKey => $post['filter_CODE'] ?? '',
                'filter_' . $libelleKey => $post['filter_LIBELLE'] ?? '',

                'tri_' . $primaryKey => $post['tri_CODE'] ?? '',
                'tri_' . $libelleKey => $post['tri_LIBELLE'] ?? '',
            ]
        );

        // TODO : paginate with fetchAll instead
        $infoPagination = (new Paginator())
            ->generate($listEntity, 8, $post, $this->renderer);

        return $this->renderer->render('@ajax-liste/listeEntity', [
            'listEntity' => $listEntity,
            'infoPagination' => $infoPagination,
            'post' => $post,
            'entity' => $entity,
            'primaryKey' => $primaryKey,
            'libelleKey' => $libelleKey,
        ]);
    }

    private function getQueryBuilder(string $s) :?QueryBuilder
    {
        switch ($s) {
            case 'ProfilTva':
                return new ProfilTva($this->pdo);
            case 'Tiers':
                return new Tiers($this->pdo);
            case 'DaModel':
                return new DaModel($this->pdo);
            default:
        }
        return null;
    }

    public function doaAction(): string
    {
        /**
         * "getParsedBody()" : permet de récupérer les données dans la variable $_POST (c'est le getParsedBody() qu'on stocke dans $post
         * $_POST est une variable superglobale utilisée pour collecté les données dans un formulaire HTML via la méthode "post"
         *
         * "request->" : méthode de la classe Controller. Est-ce un objet utilisé comme fonction grâce à la méthode __invoke ?????????????????
         */
        $post = $this->request->getParsedBody();


        /**
         * "$entity" : objet de type Entity qui permet d'executer des requêtes simplexml_load_string
         * "Doa($this->pdo)" : récupère la classe PDO pour l'accès à la BDD
         * "$listeEntity" :
         */
        $entity = new \Entity\Model\Doa($this->pdo);
        $listeEntity = $entity->fetchAll([], $post);
        $paginator = new Paginator();

        $infoPagination = $paginator->generate($listeEntity, 8, $post, $this->renderer);

        return $this->renderer->render('@ajax-liste/listeDoa', [
            'listeEntity' => $listeEntity,
            'infoPagination' => $infoPagination,
            'post' => $post
        ]);
    }

    public function campNotExAction(): string
    {
        $post = $this->request->getParsedBody();

        $listeRepository = new \Modules\Ajax\Repository\Listes($this->pdo);
        $liste = $listeRepository->listeCampNotex($post);

        $paginator = new Paginator();

        $infoPagination = $paginator->generate($liste, 8, $post, $this->renderer);

        return $this->renderer->render('@ajax-liste/listeCampNotex', [
            'listeEntity' => $liste,
            'infoPagination' => $infoPagination,
            'post' => $post,
        ]);
    }

    public function aoFormatExcelAction(): string
    {
        $post = $this->request->getParsedBody();

        $entityGenerator = new AoExCentre($this->pdo);

        $listEntity = $entityGenerator->fetchAll([], $post);

        $paginator = new Paginator();

        $infoPagination = $paginator->generate($listEntity, 8, $post, $this->renderer);

        return $this->renderer->render('@ajax-liste/listeFormatAO', [
            'listeEntity' => $listEntity,
            'infoPagination' => $infoPagination,
            'post' => $post
        ]);
    }

    public function aoEntetAction(): string
    {
        $post = $this->request->getParsedBody();

        $gestionConsultation = new GestionConsultation($this->pdo);
        $listeEntity = $gestionConsultation->listeConsultation($post);

        $paginator = new Paginator();

        $infoPagination = $paginator->generate($listeEntity, 8, $post, $this->renderer);

        return $this->renderer->render('@ajax-liste/listeAO', [
            'entity' => $listeEntity,
            'infoPagination' => $infoPagination,
            'post' => $post,
            'path' => 'Ajax.liste.aoEntet',
        ]);
    }

    public function typeDeMarcheAction(): string
    {

        $post = $this->request->getParsedBody();

        $typeMarche = new \Entity\Model\TypeDeMarche($this->pdo);
        $typeMarche = $typeMarche->fetchAll([], $post);

        $paginator = new Paginator();

        $infoPagination = $paginator->generate($typeMarche, 8, $post, $this->renderer);

        return $this->renderer->render('@ajax-liste/listeTypeDeMarche', [
            'typeMarches' => $typeMarche,
            'infoPagination' => $infoPagination,
            'post' => $post
        ]);
    }

    public function commandeAction(): string
    {

        $post = $this->request->getParsedBody();

        $commande = new CaEntet($this->pdo);
        $commande = $commande->fetchAll([], $post);

        $paginator = new Paginator();

        $infoPagination = $paginator->generate($commande, 8, $post, $this->renderer);

        return $this->renderer->render('@ajax-liste/listeCommande', [
            'entity' => $commande,
            'infoPagination' => $infoPagination,
            'post' => $post,
            'path' => 'Ajax.liste.commande',
        ]);
    }

    public function languesAction(): string
    {
        $post = $this->request->getParsedBody();

        $entity = new Langues($this->pdo);
        $entity = $entity->fetchAll([], $post);

        $paginator = new Paginator();

        $infoPagination = $paginator->generate($entity, 8, $post, $this->renderer);

        return $this->renderer->render('@ajax-liste/listeLangue', [
            'entity' => $entity,
            'infoPagination' => $infoPagination,
            'post' => $post,
            'path' => 'Ajax.liste.langues',
        ]);
    }

    public function suiCaDatAction(): string
    {
        $post = $this->request->getParsedBody();

        $entity = new Suicadat($this->pdo);
        $entity = $entity->fetchAll([], $post);

        $paginator = new Paginator();

        $infoPagination = $paginator->generate($entity, 8, $post, $this->renderer);

        return $this->renderer->render('@ajax-liste/listeSuicadat', [
            'entity' => $entity,
            'infoPagination' => $infoPagination,
            'post' => $post,
            'path' => 'Ajax.liste.suiCaDat',
        ]);
    }

    public function douanesAction(): string
    {
        $post = $this->request->getParsedBody();

        $entity = new Douanes($this->pdo);
        $entity = $entity->fetchAll([], $post);

        $paginator = new Paginator();

        $infoPagination = $paginator->generate($entity, 8, $post, $this->renderer);

        return $this->renderer->render('@ajax-liste/listeDouanes', [
            'entity' => $entity,
            'infoPagination' => $infoPagination,
            'post' => $post,
            'path' => 'Ajax.liste.douanes',
        ]);
    }

    public function cqualiteAction(): string
    {
        $post = $this->request->getParsedBody();

        $cQualite = new Cqualite($this->pdo);
        $cQualite = $cQualite->fetchAll([], $post);

        $paginator = new Paginator();

        $infoPagination = $paginator->generate($cQualite, 8, $post, $this->renderer);

        return $this->renderer->render('@ajax-liste/listeCqualite', [
            'entity' => $cQualite,
            'infoPagination' => $infoPagination,
            'post' => $post,
            'path' => 'Ajax.liste.cqualite',
        ]);
    }

    public function messstanAction(): string
    {
        $post = $this->request->getParsedBody();

        $messstan = new Messstan($this->pdo);
        $messstan = $messstan->fetchAll([], $post);

        $paginator = new Paginator();

        $infoPagination = $paginator->generate($messstan, 8, $post, $this->renderer);

        return $this->renderer->render('@ajax-liste/listeMessstan', [
            'entity' => $messstan,
            'infoPagination' => $infoPagination,
            'post' => $post,
            'path' => 'Ajax.liste.commande',
        ]);
    }

    public function commandeModeleAction(): string
    {

        $post = $this->request->getParsedBody();

        $liste = new Listes($this->pdo);
        $commande = $liste->getListeModeleCommande($post);

        $paginator = new Paginator();

        $infoPagination = $paginator->generate($commande, 8, $post, $this->renderer);

        return $this->renderer->render('@ajax-liste/listeModeleCde', [
            'entity' => $commande,
            'infoPagination' => $infoPagination,
            'post' => $post,
            'path' => 'Ajax.liste.commandeModele',
            'MODELE' => true,
        ]);
    }

    public function typeAchatFournisAction(): string
    {
        $post = $this->request->getParsedBody();

        $typeAchat = new Listes($this->pdo);
        $typeAchat = $typeAchat->typeAchatFournisseur($post);

        $paginator = new Paginator();

        $infoPagination = $paginator->generate($typeAchat, 8, $post, $this->renderer);

        return $this->renderer->render('@ajax-liste/listeTypeAchat2', [
            'typeAchat' => $typeAchat,
            'infoPagination' => $infoPagination,
            'post' => $post,
            'path' => 'Ajax.liste.typeAchatFournis',
        ]);
    }

    public function brAction(): string
    {
        $post = $this->request->getParsedBody();

        // on vérifie si l'utilisateur est pluri ou mono société
        $user = (new Hastutil($this->pdo))
            ->find(['CODE' => $_SESSION['Session_Login']]);

        $paginator = new PaginatorGestion();
        $paginator->generate(8, "NUM_BR", "ASC");

        $listes = new Listes($this->pdo);

        // si une ligne de commande est renseignée, on veut la liste des BR qui ont réceptionné la ligne en question pour une commande donnée
        if (($post['ligneCommande'] ?? 0) != 0) {
            $br = $listes->getListBrFromOrderLine($post +
                (
                    ! Sql::toBool($user['UTIMULTI'])
                        ? ['filter_egal_CODE_STE' => $user['CODE_STE']]
                        : []
                ));
        } else {
            $br = $listes->getListeBr($post +
            (
                ! Sql::toBool($user['UTIMULTI'])
                    ? ['filter_egal_CODE_STE' => $user['CODE_STE']]
                    : []
            ));
        }

        $infoPagination = PaginatorGestion::getInfoPagination();

        return $this->renderer->render('@ajax-liste/listeBR', [
            'entity'            => $br,
            'infoPagination'    => $infoPagination,
            'post'              => $post
        ]);
    }

    public function brLigneAction(): string
    {
        $post = $this->request->getParsedBody();

        $br = new BrLigne($this->pdo);
        $br = $br->fetchAll([], $post);

        $paginator = new Paginator();

        $infoPagination = $paginator->generate($br, 8, $post, $this->renderer);

        return $this->renderer->render('@ajax-liste/listeBRLigne', [
            'entity'            => $br,
            'infoPagination'    => $infoPagination,
            'post'              => $post,
        ]);
    }

    public function fonctionAction(): string
    {
        $post = $this->request->getParsedBody();

        $fonction = new Fcontfrn($this->pdo);
        $fonction = $fonction->fetchAll([], $post);

        $paginator = new Paginator();

        $infoPagination = $paginator->generate($fonction, 8, $post, $this->renderer);

        return $this->renderer->render('@ajax-liste/listeFonction', [
            'entity' => $fonction,
            'infoPagination' => $infoPagination,
            'post' => $post
        ]);
    }

    public function fonctionUserAction(): string
    {
        $post = $this->request->getParsedBody();

        $fonction = new FoncUsr($this->pdo);
        $fonction = $fonction->fetchAll([], $post);

        $paginator = new Paginator();

        $infoPagination = $paginator->generate($fonction, 8, $post, $this->renderer);

        return $this->renderer->render('@ajax-liste/listeFonctionUser', [
            'entity' => $fonction,
            'infoPagination' => $infoPagination,
            'post' => $post
        ]);
    }

    public function utilisateurAction(): string
    {
        $type = $this->request->getAttribute('type');
        $post = $this->request->getParsedBody();
        
        if (!isset($post['tri_CODE'])) {
            $post['tri_CODE'] = 'asc';
        }
        
        if (!isset($post['tri_NOM'])) {
            $post['tri_NOM'] = 'asc';
        }
        
        $paginator = new \Helpers\Pagination\PaginatorGestion();
        $paginator->generate(8, 'CODE', 'ASC');

        $liste = new \Modules\Ajax\Repository\Listes($this->pdo);
        if ($type == 'userOxalink') {
            $userOxalink = $liste->utilisateursOxalink($post);
            $nbrUserOxalink = count($userOxalink);

            $listeUser = $userOxalink;

            $hastutil = $liste->utilisateurListe([]);
            $nbrUser = count($hastutil);
        } else {
            if (($post['oxalink'] ?? 0) == '1'
                && (new LicenceOxalys($this->pdo))->hasOxalink()
            ) {
                $userOxalink = $liste->utilisateursOxalink([]);
                $nbrUserOxalink = count($userOxalink);
            }

            if ($type=='MAGASIN') {
                $post['MAGASIN'] = true;
            }

            $hastutil = $liste->utilisateurListe($post);
            $nbrUser = count($hastutil);
            $listeUser = $hastutil;
        }

        $infoPagination = PaginatorGestion::getInfoPagination();

        return $this->renderer->render('@ajax-liste/listeUtilisateur', [
            'utilisateurs'    => $listeUser,
            'infoPagination'  => $infoPagination,
            'post'            => $post,
            'pathUser'        => 'Ajax.liste.utilisateur',
            'nbrUser'         => $nbrUser,
            'nbrUserOxalink'  => $nbrUserOxalink ?? 0,
            'type'            => $type,
        ]);
    }

    // public function domfonctAction(): string
    // {
    //     $post = $this->request->getParsedBody();
    //     $list = (new DomaineFonctionnel($this->pdo))->fetchAll([], $post);

    //     $paginator = new Paginator();
    //     $infoPagination = $paginator->generate($list, 8, $post, $this->renderer);

    //     return $this->renderer->render('@ajax-liste/listeDomFonc', [
    //         'entity' => $list,
    //         'infoPagination' => $infoPagination,
    //         'post' => $post,
    //     ]);
    // }
    public function delegataireAction(): string
    {
        $post = $this->request->getParsedBody();
        $paginator = new \Helpers\Pagination\PaginatorGestion();
        $paginator->generate(8, 'CODE_STE', 'ASC');
        $listeUser = (new Listes($this->pdo))->listDeleg(
            $post['CODE_STE'] ?? '',
            $post
        );

        $infoPagination = PaginatorGestion::getInfoPagination();
        
        return $this->renderer->render('@ajax-liste/listeUtilisateurSimple', [
            'utilisateurs' => $listeUser,
            'infoPagination' => $infoPagination,
            'post' => $post,
            'listParam' => ['CODE_STE', ''],
        ]);
    }

    public function acheteurUserAction(): string
    {
        $post = $this->request->getParsedBody();
        $post['ACHETEUR'] = SQL::setBoolSql(1);
        unset($post['filter_ACHETEUR']);
        $paginator = new \Helpers\Pagination\PaginatorGestion();
        $paginator->generate(8, 'CODE', 'ASC');

        $hastutil = new Listes($this->pdo);
        $hastutil = $hastutil->utilisateurListe($post);

        $infoPagination = PaginatorGestion::getInfoPagination();

        return $this->renderer->render('@ajax-liste/listeUtilisateur', [
            'utilisateurs' => $hastutil,
            'infoPagination' => $infoPagination,
            'post' => $post,
            'pathUser' => 'Ajax.liste.acheteurUser',
        ]);
    }

    public function demandeurAction(): string
    {
        $post = $this->request->getParsedBody();
        $post['DEMAND'] = SQL::setBoolSql(1);
        $paginator = new \Helpers\Pagination\PaginatorGestion();
        $paginator->generate(8, 'CODE', 'ASC');

        $hastutil = new Listes($this->pdo);
        $hastutil = $hastutil->utilisateurListe($post);

        $infoPagination = PaginatorGestion::getInfoPagination();

        return $this->renderer->render('@ajax-liste/listeUtilisateur', [
            'utilisateurs' => $hastutil,
            'infoPagination' => $infoPagination,
            'post' => $post,
            'pathUser' => 'Ajax.liste.demandeur',
        ]);
    }

    public function sigFactAction(): string
    {
        $post = $this->request->getParsedBody();
        $post['SIG_BAP'] = SQL::setBoolSql(1);
        $post['VALIDE'] = SQL::setBoolSql(1);
        $paginator = new \Helpers\Pagination\PaginatorGestion();
        $paginator->generate(8, 'CODE', 'ASC');

        $hastutil = new Listes($this->pdo);
        $hastutil = $hastutil->utilisateurListe($post);

        $paginator = new Paginator();
        $infoPagination = PaginatorGestion::getInfoPagination();


        return $this->renderer->render('@ajax-liste/listeUtilisateur', [
            'utilisateurs' => $hastutil,
            'infoPagination' => $infoPagination,
            'post' => $post,
            'pathUser' => 'Ajax.liste.sigFact',
        ]);
    }

    public function sigCdeAction(): string
    {
        $post = $this->request->getParsedBody();
        $post['SIG_CDE'] = SQL::setBoolSql(1);
        $post['VALIDE'] = SQL::setBoolSql(1);
        $paginator = new \Helpers\Pagination\PaginatorGestion();
        $paginator->generate(8, 'CODE', 'ASC');

        $hastutil = new Listes($this->pdo);
        $hastutil = $hastutil->utilisateurListe($post);

        $infoPagination = PaginatorGestion::getInfoPagination();


        return $this->renderer->render('@ajax-liste/listeUtilisateur', [
            'utilisateurs' => $hastutil,
            'infoPagination' => $infoPagination,
            'post' => $post,
            'pathUser' => 'Ajax.liste.sigCde',
        ]);
    }

    public function sigDAAction(): string
    {
        $post = $this->request->getParsedBody();
        $post['SIG_DA'] = SQL::setBoolSql(1);
        $post['VALIDE'] = SQL::setBoolSql(1);
        $paginator = new \Helpers\Pagination\PaginatorGestion();
        $paginator->generate(8, 'CODE', 'ASC');

        $hastutil = new Listes($this->pdo);
        $hastutil = $hastutil->utilisateurListe($post);

        $infoPagination = PaginatorGestion::getInfoPagination();


        return $this->renderer->render('@ajax-liste/listeUtilisateur', [
            'utilisateurs' => $hastutil,
            'infoPagination' => $infoPagination,
            'post' => $post,
            'pathUser' => 'Ajax.liste.sigDA',
        ]);
    }

    public function societeAction(): string
    {
        $post = $this->request->getParsedBody();
        if (!isset($post['tri_CODE_STE'])) {
            $post['tri_CODE_STE'] = 'asc';
        }

        $societes = (new Societe($this->pdo))->listUserSociete($post);

        $paginator = new Paginator();
        $infoPagination = $paginator->generate($societes, 8, $post, $this->renderer);

        // TODO : merge into one query
        if (isset($post['with_CA_MODENUM'])) {
            $qbParanum = new Paramnum($this->pdo);
            foreach ($societes as &$soc) {
                $soc['ca_modenum'] = $qbParanum->getNodeNum('CA', $soc['CODE_STE']);
            }
            unset($soc);
        }


        return $this->renderer->render('@ajax-liste/listeSociete', [
            'societes' => $societes,
            'infoPagination' => $infoPagination,
            'post' => $post
        ]);
    }

    public function grpSocieteAction(): string
    {
        $post = $this->request->getParsedBody();
        if (!isset($post['tri_CODE_GRP'])) {
            $post['tri_CODE_GRP'] = 'asc';
        }

        $listeRepo = new Listes($this->pdo);
        $societes = $listeRepo->findGroupedCompanies($post);

        $paginator = new Paginator();
        $infoPagination = $paginator->generate($societes, 8, $post, $this->renderer);

        return $this->renderer->render('@ajax-liste/listeGrpSociete', [
            'societes' => $societes,
            'infoPagination' => $infoPagination,
            'post' => $post
        ]);
    }

    /* Utile pour l'historique fournisseur (ajout d'une ligne GLOBAL dans la liste */
    public function societeHistoriqueAction(): string
    {
        $post = $this->request->getParsedBody();

        $repo = new Societe($this->pdo);
        $societes = $repo->listUserSociete($post);

        $paginator = new Paginator();
        $infoPagination = $paginator->generate($societes, 8, $post, $this->renderer);

        return $this->renderer->render('@ajax-liste/listeSocieteHisto', [
            'societes' => $societes,
            'infoPagination' => $infoPagination,
            'post' => $post,
            'multiSoc' => $repo::hasMultiSoc(),
        ]);
    }

    public function conditionPaiementAction(): string
    {

        $post = $this->request->getParsedBody();

        $liste = new Listes($this->pdo);
        $conditionDePaiements = $liste->ConditionPaiement($post);

        $paginator = new Paginator();
        $infoPagination = $paginator->generate($conditionDePaiements, 8, $post, $this->renderer);


        return $this->renderer->render('@ajax-liste/listeConditionDePaiement', [
            'conditionDePaiements' => $conditionDePaiements,
            'infoPagination' => $infoPagination,
            'post' => $post
        ]);
    }

    public function modePaiementAction(): string
    {
        $post = $this->request->getParsedBody();

        $liste = new Listes($this->pdo);
        $modeDePaiements = $liste->modePaiement($post);

        $paginator = new Paginator();
        $infoPagination = $paginator->generate($modeDePaiements, 8, $post, $this->renderer);


        return $this->renderer->render('@ajax-liste/listeModeDePaiement', [
            'modeDePaiements' => $modeDePaiements,
            'infoPagination' => $infoPagination,
            'post' => $post
        ]);
    }


    public function modelivraisonAction(): string
    {
        $post = $this->request->getParsedBody();

        $liste = new Listes($this->pdo);
        $modeDeLivraisons = $liste->modeLivraison($post);

        $paginator = new Paginator();
        $infoPagination = $paginator->generate($modeDeLivraisons, 8, $post, $this->renderer);


        return $this->renderer->render('@ajax-liste/listeModeDeLivraison', [
            'modeDeLivraisons' => $modeDeLivraisons,
            'infoPagination' => $infoPagination,
            'post' => $post
        ]);
    }

    public function fournisseurAction(): string
    {
        $post = $this->request->getParsedBody();
        $type = $this->request->getAttribute('type') ?? '';

        // Default tri
        if (empty(array_filter(
            array_keys($post),
            function ($s) {
                return str_starts_with($s, 'tri_');
            }
        ))) {
            $post['tri_RS'] = 'asc';
        }

        $liste = new \Modules\Ajax\Repository\Listes($this->pdo);

        if (sql::toBool($post['advancedPopup'] ?? false)) {
            $outilRechercheService = new OutilRechercheService($this->pdo);
            $centre         = $outilRechercheService->getCentreRecherche();
            $rechercheRepo  = new Recherche($this->pdo);

            $listeZoneGeoCentre = $liste->listeZoneGeoCentre($centre);
            $zoneGeo = [];
            foreach ($listeZoneGeoCentre as $ZG) {
                $zoneGeo[] = $ZG['zoneGeo'];
            }

            $post['activeZone'] = $rechercheRepo->zoneGeoActive($centre)['active'];
            $post['centre'] = $centre;
        }
        
        $post['typeActif'] = $type;
        $afficheTouslesfournisseur = true;
        $countSousFamille = 0;
        $countArtHaplus = 0;
        if (($post['callV1'] ?? false) && isset($post['Session_Langue'])) {
            $_SESSION['Session_Langue']  = $post['Session_Langue'];
        }
        if (isset($post['afficheTouslesfournisseur'])) {
            $afficheTouslesfournisseur = $post['afficheTouslesfournisseur'];
        }
        $trad = $this->getTranslationService();
        
        $listeService = new ListeService($this->pdo);
        $infoColonne = $listeService->generateChampsFournisseur($trad, $type);
        
        $listeColonne = $infoColonne['listeColonne'];
        $select = $infoColonne['select'];
        $cs = $infoColonne['cs'];

        $labelValide = $trad->t('Uniquement les valides ?');

        if (empty($post['filter_CODE']) && ($post['filter_CODE'] ?? null) !== '') {
            $post['valide'] = 1;
        } else {
            Outils::isCheck($post['valide']);
        }


        if ($type == 'suivi' || $type=='notFourn') {
            $nbrFournisseur = $liste->countFournisseur($post, $cs);
            
            $file = '@suivi/Fournisseur/SuiviFournisseur';

            if ($type == 'suivi') {
                Ariane::generate(0, $this->getTranslationService()->t('Liste des fournisseurs'), $post, $nbrFournisseur);
                $menuActive = 'eproc';
            } else {
                Ariane::generate(0, $this->getTranslationService()->t('Liste des notations fournisseurs'), $post, $nbrFournisseur);
                $menuActive = 'eproc';
                $menuLeft = 'notFourn';
            }
        } else {
            $file = '@ajax-liste/listeFournisseur';
            $menuActive = '';

            $modeSfm = false;
            $modeArt = false;
            if (isset($post['code_art_haplus']) && $post['code_art_haplus'] != '') {
                $postListeArtHaplus = $post;
                $postListeArtHaplus['typeActif'] = 'article';
                $countArtHaplus = $liste->countFournisseur($postListeArtHaplus, $cs);
                
                if ($countArtHaplus == 0 && !isset($post['passage'])) {
                    unset($post['code_art_haplus']);
                } else {
                    $modeArt = true;
                }
            }
    
            if (isset($post['code_sous_famille']) && $post['code_sous_famille'] != '') {
                $postlisteSousFamille = $post;
                $postlisteSousFamille['typeActif'] = 'sousFamille';
                $countSousFamille = $liste->countFournisseur($postlisteSousFamille, $cs);
    
                if ($countSousFamille == 0 && !isset($post['passage'])) {
                    unset($post['code_sous_famille']);
                } else {
                    $modeSfm = true;
                }
            }
    
            $postlisteAllFRS = $post;
            $postlisteAllFRS['typeActif'] = 'ALL';
            $nbrFournisseur = $liste->countFournisseur($postlisteAllFRS, $cs);
            
            if ($modeArt && $post['typeActif'] == '') {
                $post['typeActif'] = 'article';
            } elseif ($modeSfm && $post['typeActif'] == '') {
                $post['typeActif'] = 'sousFamille';
            }
        }
        
        if (($post['callV1'] ?? false)) {
            $file = '@ajax-liste/listeFournisseurV1';
        }

        $paginator = new \Helpers\Pagination\PaginatorGestion();
        $paginator->generate(($type=='suivi' || $type == 'notFourn')? 0:12, 'RS', 'ASC');
        

        $fournisseur = $liste->Fournisseur($post, $select, $cs, null, 'defaut');

        $infoPagination = PaginatorGestion::getInfoPagination();
        /** @phpstan-ignore-next-line */
        
        if (sql::toBool($post['callV1'] ?? false) || sql::toBool($post['advancedPopup'] ?? false)) {
            if ($post['colorTemplate']??'') {
                $_SESSION['infoVersion']['colorTemplate'] = $post['colorTemplate']??'';
            }
            if ($post['SESSION_SKIN_CODE']??'') {
                $_SESSION['SESSION_SKIN_CODE'] = $post['SESSION_SKIN_CODE']??'';
            }

            if ($countSousFamille != 0 || $countArtHaplus != 0) {
                $paravrac = new Paravrac($this->pdo);
                $r = $paravrac->find(['CODEPARV' => 'ARTGEN_LISTEFOURN_LIMITEE', 'TYPEPARV' => 'OXAPROC']);
                $limitationChoixFournisseur = is_array($r) && array_key_exists('LIB01PARV', $r) && $r['LIB01PARV'] == 'O';

                $user = new \Modules\Index\Repository\User($this->pdo);
                $droitVoirTousFourniss = $user->droitsUtilisateur('OX_AG_LF_L', $post['login']??'')['DROIT'];

                if (!$limitationChoixFournisseur || $droitVoirTousFourniss) {
                    $afficheTouslesfournisseur = true;
                } else {
                    $afficheTouslesfournisseur = false;
                }
            }

            if (isset($post['code_art_haplus']) && $post['code_art_haplus'] != '') {
                $articleEntity = new Articles($this->pdo);
                $article = $articleEntity->find($post['code_art_haplus']);
            }

            if (isset($post['code_sous_famille']) && $post['code_sous_famille'] != '') {
                $sousFamilleRepo = new SousFamille($this->pdo);
                $sousFamille = $sousFamilleRepo->find($post['code_sous_famille']);
            }
        }

        if ($type == '') {
            if (($post['code_sous_famille'] ?? '') != '') {
                $type = $post['typeActif'] = 'sousFamille';
            }
            if (($post['code_art_haplus'] ?? '') != '') {
                $type = $post['typeActif'] = 'article';
            }
        }

        /** Init ecran */
        $motsClefs = new MotClef($this->pdo);
        $listeMotsClef = $motsClefs->fetchAll([], [], \PDO::FETCH_ASSOC);
        if (count($listeMotsClef)) {
            $tabmotsClefs[''] = $trad->t('Tous les mots clef');
            for ($i = 0; $i < count($listeMotsClef); $i++) {
                $tabmotsClefs[$listeMotsClef[$i]['MOTCLEF']] = $listeMotsClef[$i]['MOTCLEF'];
            }
        } else {
            $tabmotsClefs = [];
        }

        $gestFourniss = new GestFourniss($this->pdo);
        $listeShortList   = $gestFourniss->listeTypeFournisseur();
        if (count($listeShortList)) {
            $tabTypeFourniss[''] = $trad->t('Tous les fournisseurs');
            for ($i = 0; $i < count($listeShortList); $i++) {
                $tabTypeFourniss[$listeShortList[$i]['LIBELLE']] = $listeShortList[$i]['LIBELLE'];
            }
        } else {
            $tabTypeFourniss = [];
        }

        $pays = new Pays($this->pdo);
        $listePaysTmp = $pays->fetchAll([], ['tri_LIBELLE' => 'asc'], \PDO::FETCH_ASSOC);
        $listePays[''] = $this->getTranslationService()->t('Tous les pays');

        foreach ($listePaysTmp as $tmpPays) {
            $listePays[$tmpPays['CODE_PAYS']] = $tmpPays['LIBELLE'];
        }

        
        return $this->renderer->render($file, [
            'menuActive' => $menuActive,
            'menuLeft' => $menuLeft??'',
            'fournisseurs' => $fournisseur,
            'infoPagination' => $infoPagination,
            'post' => $post,
            'path' => 'Ajax.liste.fournisseur',
            'listeColonne' => $listeColonne,
            'labelValide' => $labelValide,
            'callV1' => $post['callV1'] ?? false,
            'codeSousFamille' => $post['code_sous_famille'] ?? '',
            'codeArtHaplus' => $post['code_art_haplus'] ?? '',
            'type' => $type == ''? null:$type,
            'motsClefs' => $tabmotsClefs,
            'shortLists' => $tabTypeFourniss,
            'afficheTouslesfournisseur' => $afficheTouslesfournisseur,
            'Session_CreatFournOccas' => $_SESSION['Session_CreatFournOccas'],
            'nbrArticle' => $countArtHaplus,
            'nbrSousFamille' => $countSousFamille,
            'nbrFournisseurs' => $nbrFournisseur,
            'libelleArticle' => $article['DESIGN'] ?? '',
            'listePays' => $listePays,
            'libelleSfFamille' => $sousFamille['DESIGNAT'] ?? '',
        ]);
    }

    public function contactFournisseurAction(): string
    {
        $post = $this->request->getParsedBody();

        $post['email'] = isset($post['email']) && ($post['email'] == 'true' || $post['email'] == 1) ? true : false;

        $liste = new \Modules\Ajax\Repository\Listes($this->pdo);
        $contactsFournisseur = $liste->contactsFournisseur($post);

        $paginator = new Paginator();
        $infoPagination = $paginator->generate($contactsFournisseur, 8, $post, $this->renderer);

        return $this->renderer->render('@ajax-liste/listeContactFournisseur', [
            'contactsFournisseur' => $contactsFournisseur,
            'infoPagination' => $infoPagination,
            'post' => $post
        ]);
    }
    public function contactFournisseurV2Action(): string
    {
        $post = $this->request->getParsedBody();
        
        $post['email'] = Sql::toBool($post['email'] ?? false);

        $liste = new \Modules\Ajax\Repository\Listes($this->pdo);
        $contactsFournisseur = $liste->contactsFournisseur($post);

        $paginator = new Paginator();
        $infoPagination = $paginator->generate($contactsFournisseur, 8, $post, $this->renderer);

        return $this->renderer->render('@ajax-liste/listeContactFournisseurV2', [
            'contactsFournisseur' => $contactsFournisseur,
            'infoPagination' => $infoPagination,
            'post' => $post
        ]);
    }

    public function adresseFournisseurAction(): string
    {
        $post = $this->request->getParsedBody();

        $adresse = new Listes($this->pdo);
        $listeAdresse = $adresse->adresseFournisseur($post);

        $paginator = new Paginator();
        $infoPagination = $paginator->generate($listeAdresse, 8, $post, $this->renderer);

        return $this->renderer->render('@ajax-liste/listeAdresseFournisseur', [
            'listeAdresse' => $listeAdresse,
            'infoPagination' => $infoPagination,
            'post' => $post
        ]);
    }

    public function adresseCentreAction(): string
    {
        $post = $this->request->getParsedBody();

        $adresse = new Listes($this->pdo);
        $listeAdresse = $adresse->adresseCentre($post);

        $paginator = new Paginator();
        $infoPagination = $paginator->generate($listeAdresse, 8, $post, $this->renderer);

        return $this->renderer->render('@ajax-liste/listeAdresseCentre', [
            'listeAdresse' => $listeAdresse,
            'infoPagination' => $infoPagination,
            'post' => $post
        ]);
    }

    public function contactParFournisseurAction(): string
    {
        $post = $this->request->getParsedBody();

        $contactsFournisseur = new \Entity\Model\Contfour($this->pdo);
        $contactsFournisseur = $contactsFournisseur->fetchAll([], $post);

        $paginator = new Paginator();
        $infoPagination = $paginator->generate($contactsFournisseur, 8, $post, $this->renderer);


        return $this->renderer->render('@ajax-liste/listeContactParFournisseur', [
            'contactsFournisseur' => $contactsFournisseur,
            'infoPagination' => $infoPagination,
            'post' => $post
        ]);
    }

    public function contactParCentreAction(): string
    {
        $post = $this->request->getParsedBody();

        $contact = new \Entity\Model\CtcCtr($this->pdo);
        $contact = $contact->fetchAll([], $post);

        $paginator = new Paginator();
        $infoPagination = $paginator->generate($contact, 8, $post, $this->renderer);


        return $this->renderer->render('@ajax-liste/listeContactParCentre', [
            'contacts' => $contact,
            'infoPagination' => $infoPagination,
            'post' => $post
        ]);
    }

    public function deviseAction(): string
    {
        $post = $this->request->getParsedBody();

        $liste = new \Modules\Ajax\Repository\Listes($this->pdo);
        $devises = $liste->Devise($post);

        $paginator = new Paginator();
        $infoPagination = $paginator->generate($devises, 8, $post, $this->renderer);

        return $this->renderer->render('@ajax-liste/listeDevise', [
            'devises' => $devises,
            'infoPagination' => $infoPagination,
            'post' => $post
        ]);
    }


    public function caEntetAction(): string
    {
        $post = $this->request->getParsedBody();

        $liste = new \Modules\Ajax\Repository\Listes($this->pdo);
        $caEntet = $liste->CaEntet($post);
        $trad = $this->getTranslationService();

        $paginator = new Paginator();
        $infoPagination = $paginator->generate($caEntet, 8, $post, $this->renderer);

        $listeEtat = [
            'E' => $trad->t('En cours'),
            'L' => $trad->t('Livraison partielle'),
            'S' => $trad->t('Soldée physiquement')
        ];

        /**
         * SPEC 4065 AFFICHAGE DES PRIX ET MONTANTS
         * Dans le cas où $post['noprice']==1, les prix ne sont pas affichés selon les conditions suivantes :
         * 1/   SI $post['sourcePrincipale']=='BR' (Suivi de Réceptions, Création de BR, BR attendus, export BR)
         *      ET SI l'utilisateur n'a pas les droits HA_CA_VIPX et HA_BR_PX
         * 2/   Pour les autres $post['sourcePrincipale'] (autres suivi, exports...), SI l'utilisateur n'a pas le droit HA_CA_VIPX
         **/
        if ((isset($post['noprice']) && $post['noprice'])
            &&
            (
                ((isset($post['sourcePrincipale']) && $post['sourcePrincipale'] == "BR") && !\Helpers\Outil\Roles::droitsUtilisateur($this->pdo, 'HA_CA_VIPX') && !\Helpers\Outil\Roles::droitsUtilisateur($this->pdo, 'HA_BR_PX'))
                ||
                ((isset($post['sourcePrincipale']) && $post['sourcePrincipale'] != "BR") && !\Helpers\Outil\Roles::droitsUtilisateur($this->pdo, 'HA_CA_VIPX'))
            )
        ) {
            $noprice = 1;
        }

        return $this->renderer->render('@ajax-liste/listeCaEntet', [
            'caEntets' => $caEntet,
            'infoPagination' => $infoPagination,
            'post' => $post,
            'listeEtat' => $listeEtat,
            'noprice' => $noprice ?? 0,
        ]);
    }


    public function ordonanceAction(): string
    {
        $post = $this->request->getParsedBody();

        $ordonance = new \Entity\Model\Ordonanc($this->pdo);
        $ordonances = $ordonance->fetchAll([], $post);

        $paginator = new Paginator();
        $infoPagination = $paginator->generate($ordonances, 8, $post, $this->renderer);


        return $this->renderer->render('@ajax-liste/listeOrdonance', [
            'ordonances' => $ordonances,
            'infoPagination' => $infoPagination,
            'post' => $post
        ]);
    }

    public function regroupAction(): string
    {
        $post = $this->request->getParsedBody();

        $Regroup = new \Entity\Model\Regroupement($this->pdo);
        $Regroup = $Regroup->fetchAll([], $post);

        $paginator = new Paginator();
        $infoPagination = $paginator->generate($Regroup, 8, $post, $this->renderer);


        return $this->renderer->render('@ajax-liste/listeRegroupement', [
            'entity' => $Regroup,
            'infoPagination' => $infoPagination,
            'post' => $post
        ]);
    }


    public function siAction(): string
    {
        $post = $this->request->getParsedBody();
        $trad = $this->getTranslationService();

        $paginator = new \Helpers\Pagination\PaginatorGestion();
        $infoPagination = $paginator->generate(8, 'ID_SI', 'ASC');

        $liste = new \Modules\Ajax\Repository\Listes($this->pdo);
        $si = $liste->SectionImputation($post, $post['panier'] ?? false);

        $infoPagination = \Helpers\Pagination\PaginatorGestion::getInfoPagination();

        $moduleParam = new \Modules\GlobalApplication\Repository\Param($this->pdo);
        $devise_base = $moduleParam->AllParamsGetValue('DEVISE_BASE');

        $today = Date::dateConverte(Date('Ymd'));
        $labelValide = Trad::strBuild($trad->t('Uniquement les SI valides au @1@ ?'), $today);

        if (isset($post['filter_date_DATE_DEB']) && $post['filter_date_DATE_DEB'] != '') {
            \Helpers\Outil\Date::dateToSql($post['filter_date_DATE_DEB']);
        }
        if (isset($post['filter_date_DATE_FIN']) && $post['filter_date_DATE_FIN'] != '') {
            \Helpers\Outil\Date::dateToSql($post['filter_date_DATE_FIN']);
        }

        return $this->renderer->render('@ajax-liste/listeSi', [
            'sis' => $si,
            'infoPagination' => $infoPagination,
            'post' => $post,
            'labelValide' => $labelValide,
            'sectorise' => \Helpers\Outil\Roles::droit($this->pdo, 'SISECTOR', 'PARAMSTE'),
            'devise_base' => $devise_base,
        ]);
    }

    /*public function codeCompAction() : string
    {
        $post = $this->request->getParsedBody();

        $paginator = new \Helpers\Pagination\PaginatorGestion();
        $infoPagination = $paginator->generate(8, 'CODECOMP.CODE_CDC');

        $liste = new \Modules\Ajax\Repository\Listes($this->pdo);
        $listeCodeComp = $liste->listeCodeComp($post);

        $infoPagination = \Helpers\Pagination\PaginatorGestion::getInfoPagination();

        return $this->renderer->render('@ajax-liste/listeCodeComplementaire', [
            'listeCodecomp' => $listeCodeComp,
            'infoPagination' => $infoPagination,
            'post' => $post,
        ]);
    }*/

    public function cdcAction(): string
    {
        $post = $this->request->getParsedBody();
        $trad = $this->getTranslationService();
        
        $paginator = new \Helpers\Pagination\PaginatorGestion();
        $infoPagination = $paginator->generate(8, 'ID_CDC', 'ASC');
        $liste = new \Modules\Ajax\Repository\Listes($this->pdo);
        $cdc = $liste->Cdc($post);
        
        $infoPagination = \Helpers\Pagination\PaginatorGestion::getInfoPagination();

        $today = Date::dateConverte(Date('Ymd'));
        $labelValide = Trad::strBuild($trad->t('Uniquement les CDC valides au @1@ ?'), $today);

        return $this->renderer->render('@ajax-liste/listeCdc', [
            'cdcs' => $cdc,
            'infoPagination' => $infoPagination,
            'post' => $post,
            'labelValide' => $labelValide,
        ]);
    }

    public function scaAction(): string
    {
        $post = $this->request->getParsedBody();

        $paginator = new \Helpers\Pagination\PaginatorGestion();
        $infoPagination = $paginator->generate(8, 'ID_SCA', 'ASC');

        $liste = new \Modules\Ajax\Repository\Listes($this->pdo);
        $sca = $liste->Sca($post);

        $infoPagination = \Helpers\Pagination\PaginatorGestion::getInfoPagination();

        $trad = $this->getTranslationService();
        $today = Date::dateConverte(Date('Ymd'));
        $labelValide = Trad::strBuild($trad->t('Uniquement les SCA valides au @1@ ?'), $today);

        return $this->renderer->render('@ajax-liste/listeSca', [
            'scas' => $sca,
            'infoPagination' => $infoPagination,
            'post' => $post,
            'labelValide' => $labelValide,
            'sectorise' => \Helpers\Outil\Roles::droit($this->pdo, 'SCASECTO', 'PARAMSTE'),
        ]);
    }

    public function centreAction(): string
    {
        $post = $this->request->getParsedBody();

        if (isset($post['paramPopup'])) {
            $paramPopup = json_decode($post['paramPopup'], true);
            $postTMP = [];
            foreach ($paramPopup as $param) {
                $postTMP[$param['name']] = $param['value'];
            }
            $postTMP['tokenCSRF'] = $post['tokenCSRF'];

            $post = $postTMP;
        }

        $centre = new \Entity\Model\Centre($this->pdo);
        $centre = $centre->fetchAll([], $post);

        $menuContextuel = new CentresContextuel($this->pdo, $this->router, $this->getTranslationService());
        foreach ($centre as &$ctr) {
            $ctr['menuContextuel'] = $menuContextuel->generate($ctr, true);
        }

        $paginator = new Paginator();
        $infoPagination = $paginator->generate($centre, 8, $post, $this->renderer);

        return $this->renderer->render('@ajax-liste/ListeCentre', [
            'centres' => $centre,
            'infoPagination' => $infoPagination,
            'post' => $post,
            'path' => 'Ajax.liste.centre',
        ]);
    }

    public function centreEmetteurAction(): string
    {
        $post = $this->request->getParsedBody();

        $liste = new \Modules\Ajax\Repository\Listes($this->pdo);
        $centre = $liste->CentreEmetteur($post['code_ste'] ?? '', $post);


        $menuContextuel = new CentresContextuel($this->pdo, $this->router, $this->getTranslationService());
        foreach ($centre as &$ctr) {
            $ctr['menuContextuel'] = $menuContextuel->generate($ctr, true);
        }

        $paginator = new Paginator();
        $infoPagination = $paginator->generate($centre, 8, $post, $this->renderer);

        return $this->renderer->render('@ajax-liste/ListeCentre', [
            'centres' => $centre,
            'infoPagination' => $infoPagination,
            'post' => $post,
            'path' => 'Ajax.liste.centreEmetteur',
        ]);
    }

    public function centreLivraisonAction(): string
    {
        $post = $this->request->getParsedBody();
        $liste = new \Modules\Ajax\Repository\Listes($this->pdo);
        $centre = $liste->CentreLivraison(($post['code_ste'] ?? ''), $post);

        $menuContextuel = new CentresContextuel($this->pdo, $this->router, $this->getTranslationService());
        foreach ($centre as &$ctr) {
            $ctr['menuContextuel'] = $menuContextuel->generate($ctr, true);
        }

        $paginator = new Paginator();
        $infoPagination = $paginator->generate($centre, 8, $post, $this->renderer);

        return $this->renderer->render('@ajax-liste/ListeCentre', [
            'centres' => $centre,
            'infoPagination' => $infoPagination,
            'post' => $post,
            'path' => 'Ajax.liste.centreLivraison',
        ]);
    }

    // Les centres de livraison ci-dessous vont nous retourner tout le contenue de la liste des centres de livraison et centre metteur sans filtres

    public function centreEmetteurAllAction(): string
    {
        $post = $this->request->getParsedBody();

        $liste = new \Modules\Ajax\Repository\Listes($this->pdo);
        $centre = $liste->CentreEmetteur('', $post);

        $menuContextuel = new CentresContextuel($this->pdo, $this->router, $this->getTranslationService());
        foreach ($centre as &$ctr) {
            $ctr['menuContextuel'] = $menuContextuel->generate($ctr, true);
        }

        $paginator = new Paginator();
        $infoPagination = $paginator->generate($centre, 8, $post, $this->renderer);

        return $this->renderer->render('@ajax-liste/listeCentre', [
            'centres' => $centre,
            'infoPagination' => $infoPagination,
            'post' => $post,
            'path' => 'Ajax.liste.centreEmetteurAll',
        ]);
    }

    /**
     * centreEmetteurByTypeAction
     *
     * Cette fonction va retourner la liste des centres en fonction du parametre tels que
     * $param : LIVRAISON = TRUE OR EMISSION = TRUE OR FACTURATION = TRUE
     *
     */
    public function centreByTypeAction(): string
    {
        $post = $this->request->getParsedBody();

        $id = $this->request->getAttribute('typeCentre');

        $liste = new \Modules\Ajax\Repository\Listes($this->pdo);
        $centre = $liste->centreByType($id, $post);

        $menuContextuel = new CentresContextuel($this->pdo, $this->router, $this->getTranslationService());
        foreach ($centre as &$ctr) {
            $ctr['menuContextuel'] = $menuContextuel->generate($ctr, true);
        }


        $paginator = new Paginator();
        $infoPagination = $paginator->generate($centre, 8, $post, $this->renderer);

        return $this->renderer->render('@ajax-liste/listeCentreByType', [
            'centres' => $centre,
            'infoPagination' => $infoPagination,
            'path' => 'Ajax.liste.centreByType',
            'id' => $id,
            'post' => $post
        ]);
    }

    public function centreLivraisonAllAction(): string
    {
        $post = $this->request->getParsedBody();

        $liste = new \Modules\Ajax\Repository\Listes($this->pdo);
        $centre = $liste->CentreLivraison('', $post);

        $paginator = new Paginator();
        $infoPagination = $paginator->generate($centre, 8, $post, $this->renderer);

        return $this->renderer->render('@ajax-liste/listeCentre', [
            'centres' => $centre,
            'infoPagination' => $infoPagination,
            'post' => $post,
            'path' => 'Ajax.liste.centreLivraisonAll',
        ]);
    }


    //______________FIN_________________



    // DEBUT IMPRIMER ACCORD DE CADRE ::

    public function typeAchatWithoutAction(): string
    {
        $post = $this->request->getParsedBody();

        $liste = new \Modules\Ajax\Repository\Listes($this->pdo);

        $typeAchatWithout = $liste->typeAchatWithout($post['idFourniss']);

        $paginator = new Paginator();
        $infoPagination = $paginator->generate($typeAchatWithout, 8, $post, $this->renderer);

        return $this->renderer->render('@ajax-liste/listeTypeAchat', [
            'typeAchatWithout' => $typeAchatWithout,
            'infoPagination' => $infoPagination,
            'post' => $post
        ]);
    }

    public function typeDeDocumentAction(): string
    {
        $post = $this->request->getParsedBody();

        $typeAll = new \Entity\Model\TypeDoc($this->pdo);
        $typeAll = $typeAll->fetchAll([], $post);


        $paginator = new Paginator();
        $infoPagination = $paginator->generate($typeAll, 8, $post, $this->renderer);

        return $this->renderer->render('@ajax-liste/listeTypeDeDocument', [
            'typeDeDocument' => $typeAll,
            'infoPagination' => $infoPagination,
            'post' => $post
        ]);
    }
    public function fournisseurImpressionAction(): string
    {
        $post = $this->request->getParsedBody();
        $liste = new \Modules\Ajax\Repository\Listes($this->pdo);
        $fournisseurImpression = $liste->fournisseurImpression('74777');

        $paginator = new Paginator();
        $infoPagination = $paginator->generate($fournisseurImpression, 8, $post, $this->renderer);

        return $this->renderer->render('@ajax-liste/listeFournisseurImpression', [
            'fournisseurImpression' => $fournisseurImpression,
            'infoPagination' => $infoPagination,
            'post' => $post
        ]);
    }

    public function centreLivraisonImpressionAction(): string
    {

        $post = $this->request->getParsedBody();


        $liste = new \Modules\Ajax\Repository\Listes($this->pdo);
        $centreLiv = $liste->centreLivraisonImpression($post['codeSte']);

        $paginator = new Paginator();
        $infoPagination = $paginator->generate($centreLiv, 8, $post, $this->renderer);

        return $this->renderer->render('@ajax-liste/listeCentre', [
            'centreLiv' => $centreLiv,
            'infoPagination' => $infoPagination,
            'post' => $post,
            'path' => 'Ajax.liste.centreLivraisonImpression'
        ]);
    }


    public function centreEmetteurImpressionAction(): string
    {

        $post = $this->request->getParsedBody();


        $liste = new \Modules\Ajax\Repository\Listes($this->pdo);
        $centreEmetteur = $liste->centreEmetteurImpression($post['codeSte']);
        ;

        $paginator = new Paginator();
        $infoPagination = $paginator->generate($centreEmetteur, 8, $post, $this->renderer);

        return $this->renderer->render('@ajax-liste/listeEmetteurImpression', [
            'centreEm' => $centreEmetteur,
            'infoPagination' => $infoPagination,
            'post' => $post
        ]);
    }
    public function societeImpressionAction(): string
    {

        $post = $this->request->getParsedBody();

        $liste = new \Modules\Ajax\Repository\Listes($this->pdo);
        $societe = $liste->societeImpression($post['codeAcd']);


        $paginator = new Paginator();
        $infoPagination = $paginator->generate($societe, 8, $post, $this->renderer);

        return $this->renderer->render('@ajax-liste/listeSocieteImpression', [
            'societe' => $societe,
            'infoPagination' => $infoPagination,
            'post' => $post
        ]);
    }
    // FIN IMPRESSION D'ACCORD CADRE
    public function acdRespAction(): string
    {
        $post = $this->request->getParsedBody();

        $liste = new \Modules\Ajax\Repository\Listes($this->pdo);
        $acd = $liste->societeImpression($post['codeAcd']);


        $paginator = new Paginator();
        $infoPagination = $paginator->generate($acd, 8, $post, $this->renderer);

        return $this->renderer->render('@ajax-liste/listeSocieteImpression', [
            'acd' => $acd,
            'infoPagination' => $infoPagination,
            'post' => $post
        ]);
    }
    public function typeAchatAction(): string
    {
        $post = $this->request->getParsedBody();

        $liste = new listes($this->pdo);

        $typeAchat = $liste->typeAchat($post);

        $paginator = new Paginator();
        $infoPagination = $paginator->generate($typeAchat, 8, $post, $this->renderer);

        return $this->renderer->render('@ajax-liste/listeTypeAchat2', [
            'typeAchat' => $typeAchat,
            'infoPagination' => $infoPagination,
            'post' => $post,
            'path' => 'Ajax.liste.typeAchat'
        ]);
    }

    public function motClefAction(): string
    {
        $post = $this->request->getParsedBody();

        $liste = new MotClef($this->pdo);

        $motClef = $liste->fetchAll([], $post);

        $paginator = new Paginator();
        $infoPagination = $paginator->generate($motClef, 8, $post, $this->renderer);

        return $this->renderer->render('@ajax-liste/listeMotClef', [
            'entity' => $motClef,
            'infoPagination' => $infoPagination,
            'post' => $post,
        ]);
    }

    public function domaineCompetenceAction(): string
    {
        $post = $this->request->getParsedBody();

        $liste = new DomaineCompetence($this->pdo);
        $entity = $liste->fetchAll([], $post);

        $paginator = new Paginator();
        $infoPagination = $paginator->generate($entity, 8, $post, $this->renderer);

        return $this->renderer->render('@ajax-liste/listeDomComp', [
            'entity' => $entity,
            'infoPagination' => $infoPagination,
            'post' => $post,
        ]);
    }

    public function paysAction(): string
    {

        $post = $this->request->getParsedBody();

        $Pays = new \Entity\Model\Country($this->pdo);
        $Pays = $Pays->fetchAll([], $post);

        $paginator = new Paginator();
        $infoPagination = $paginator->generate($Pays, 8, $post, $this->renderer);

        return $this->renderer->render('@ajax-liste/listePays', [
            'listPays' => $Pays,
            'infoPagination' => $infoPagination,
            'post' => $post
        ]);
    }

    public function domaineFonctionnelleAction(): string
    {

        $post = $this->request->getParsedBody();

        $DomaineFonctionnelle = new \Entity\Model\DomaineFonctionnel($this->pdo);
        $DomaineFonctionnelle = $DomaineFonctionnelle->fetchAll([], $post);

        $paginator = new Paginator();
        $infoPagination = $paginator->generate($DomaineFonctionnelle, 8, $post, $this->renderer);

        return $this->renderer->render('@ajax-liste/listePays', [
            'lisetDomaineFonctionnelle' => $DomaineFonctionnelle,
            'infoPagination' => $infoPagination,
            'post' => $post
        ]);
    }

    public function domaineFonctionnelAction(): string
    {

        $post = $this->request->getParsedBody();

        $DomaineFonctionnel = new \Entity\Model\DomaineFonctionnel($this->pdo);
        $DomaineFonctionnel = $DomaineFonctionnel->fetchAll([], $post);

        $paginator = new Paginator();
        $infoPagination = $paginator->generate($DomaineFonctionnel, 8, $post, $this->renderer);

        return $this->renderer->render('@ajax-liste/listeDomaineFonctionnel', [
            'domainesfonctionnels'  => $DomaineFonctionnel,
            'infoPagination'        => $infoPagination,
            'post'                  => $post
        ]);
    }

    public function decoupageAction(): string
    {

        $post = $this->request->getParsedBody();

        $Decoupage = new \Entity\Model\Decoupage($this->pdo);
        $Decoupage = $Decoupage->fetchAll([], $post);

        $paginator = new Paginator();
        $infoPagination = $paginator->generate($Decoupage, 8, $post, $this->renderer);

        return $this->renderer->render('@ajax-liste/listeDecoupage', [
            'listeDecoupage' => $Decoupage,
            'infoPagination' => $infoPagination,
            'post' => $post
        ]);
    }

    public function articlesAction(): string
    {

        $post = $this->request->getParsedBody();

        $paginator = new \Helpers\Pagination\PaginatorGestion();
        $paginator->generate(8, 'CODE_ART');

        if (empty($post['filter_CODE_ART']) && ($post['filter_CODE_ART'] ?? null) !== '') {
            $post['valide'] = 1;
        } else {
            Outils::isCheck($post['valide']);
        }

        $liste = new Listes($this->pdo);
        $items = [];

        if (($post['art_acd'] ?? '') != '') {
            $items = $liste->getFrameworkItems($post);
        }

        if (($post['art_fou'] ?? '') != '' && empty($items)) {
            // si un fournisseur est renseigné on cherche uniquement les articles liés au fournisseur
            $items = $liste->getSupplierItems($post);
        }
        
        if (($post['art_acd'] ?? '') == '' && ($post['art_fou'] ?? '') == '' && empty($items)) {
            $items = $liste->listeArticles($post);
        }

        $trad = $this->getTranslationService();

        $labelValide = $trad->t('Uniquement les valides ?');

        $infoPagination = PaginatorGestion::getInfoPagination();

        return $this->renderer->render('@ajax-liste/listeArticles', [
            'listeArticles' => $items,
            'infoPagination' => $infoPagination,
            'post' => $post,
            'pathPopup' => 'Ajax.liste.articles',
            'labelValide' => $labelValide,
        ]);
    }

    public function articlesFraisPortAction(): string
    {
        $post = $this->request->getParsedBody();

        $post['filter_egal_ARTFRAISPORT'] = 'T';

        $liste = new Listes($this->pdo);
        $Articles = $liste->listeArticles($post);
        $trad = $this->getTranslationService();

        $labelValide = $trad->t('Uniquement les valides ?');

        $paginator = new Paginator();
        $infoPagination = $paginator->generate($Articles, 8, $post, $this->renderer);

        return $this->renderer->render('@ajax-liste/listeArticles', [
            'listeArticles' => $Articles,
            'infoPagination' => $infoPagination,
            'post' => $post,
            'pathPopup' => 'Ajax.liste.articlesFraisPort',
            'labelValide' => $labelValide,
        ]);
    }

    public function marchesAction(): string
    {

        $post = $this->request->getParsedBody();

        $post['tri_LIBELLE'] = 'asc';
        $marches = new \Modules\Ajax\Repository\Listes($this->pdo);
        $marches = $marches->marches($post);

        $paginator = new Paginator();
        $infoPagination = $paginator->generate($marches, 8, $post, $this->renderer);

        return $this->renderer->render('@ajax-liste/listeMarches', [
            'listeMarches' => $marches,
            'infoPagination' => $infoPagination,
            'post' => $post
        ]);
    }

    public function accadreAction(): string
    {

        $post = $this->request->getParsedBody();

        $liste = new \Modules\Ajax\Repository\Listes($this->pdo);
        $accadre = $liste->AccordCadre($post);

        $paginator = new Paginator();
        $infoPagination = $paginator->generate($accadre, 8, $post, $this->renderer);


        return $this->renderer->render('@ajax-liste/listeAccadre', [
            'accadres' => $accadre,
            'infoPagination' => $infoPagination,
            'post' => $post
        ]);
    }

    public function acheteurAction(): string
    {
        $post = $this->request->getParsedBody();

        $liste = new \Modules\Ajax\Repository\Listes($this->pdo);
        $acheteurs = $liste->acheteur($post);

        $paginator = new Paginator();
        $infoPagination = $paginator->generate($acheteurs, 8, $post, $this->renderer);

        return $this->renderer->render('@ajax-liste/listeAcheteur', [
            'acheteurs' => $acheteurs,
            'infoPagination' => $infoPagination,
            'post' => $post
        ]);
    }

    public function utilisateurSocieteAction(): string
    {

        $post = $this->request->getParsedBody();
        $post['email'] = isset($post['email']) && ($post['email'] == 'true' || $post['email'] == 1) ? true : false;
        $paginator = new \Helpers\Pagination\PaginatorGestion();
        $paginator->generate(8, 'CODE', 'ASC');

        $liste = new \Modules\Ajax\Repository\Listes($this->pdo);
        $utilisateurs = $liste->utilisateurSociete($post);

        $infoPagination = PaginatorGestion::getInfoPagination();

        return $this->renderer->render('@ajax-liste/listeUtilisateurSociete', [
            'utilisateurs' => $utilisateurs,
            'infoPagination' => $infoPagination,
            'post' => $post
        ]);
    }

    public function sousFamilleAction(): string
    {
        $post = $this->request->getParsedBody();


        $liste = new \Modules\Ajax\Repository\Listes($this->pdo);
        $sousFamilles = $liste->sousFamille($post);

        $paginator = new Paginator();
        $infoPagination = $paginator->generate($sousFamilles, 8, $post, $this->renderer);


        return $this->renderer->render('@ajax-liste/listeSousFamille', [
            'sousFamilles' => $sousFamilles,
            'infoPagination' => $infoPagination,
            'post' => $post
        ]);
    }

    public function typeTVAAction(): string
    {

        $post = $this->request->getParsedBody();

        $typeTVA = new \Entity\Model\TypeTVA($this->pdo);
        $typeTVA = $typeTVA->fetchAll([], $post);

        $paginator = new Paginator();
        $infoPagination = $paginator->generate($typeTVA, 8, $post, $this->renderer);


        return $this->renderer->render('@ajax-liste/listeTypeTVA', [
            'typeTVA' => $typeTVA,
            'infoPagination' => $infoPagination,
            'post' => $post
        ]);
    }

    public function TVAAction(): string
    {

        $post = $this->request->getParsedBody();

        $TVA = new \Entity\Model\TVA($this->pdo);
        $TVA = $TVA->fetchAll([], $post);

        $paginator = new Paginator();
        $infoPagination = $paginator->generate($TVA, 8, $post, $this->renderer);


        return $this->renderer->render('@ajax-liste/listeTVA', [
            'TVA' => $TVA,
            'infoPagination' => $infoPagination,
            'post' => $post
        ]);
    }

    // phpcs:ignore
    public function FormatAction(): string
    {

        $post = $this->request->getParsedBody();

        $BceFexp = new BceFexp($this->pdo);
        $BceFexp = $BceFexp->FetchAll([], $post);

        $paginator = new Paginator();
        $infoPagination = $paginator->generate($BceFexp, 8, $post, $this->renderer);


        return $this->renderer->render('@ajax-liste/listeFormat', [
            'format' => $BceFexp,
            'infoPagination' => $infoPagination,
            'post' => $post
        ]);
    }

    // phpcs:ignore
    public function FabricantAction(): string
    {
        $post = $this->request->getParsedBody();

        $fabricant = new Fabricant($this->pdo);
        $fabricant = $fabricant->FetchAll([], $post);

        $paginator = new Paginator();
        $infoPagination = $paginator->generate($fabricant, 8, $post, $this->renderer);


        return $this->renderer->render('@ajax-liste/listeFabricant', [
            'ListeFabricant' => $fabricant,
            'infoPagination' => $infoPagination,
            'post' => $post
        ]);
    }

    // phpcs:ignore
    public function GammeAction(): string
    {
        $post = $this->request->getParsedBody();

        $Gamme = new Gamme($this->pdo);
        $Gamme = $Gamme->FetchAll([], $post);

        $paginator = new Paginator();
        $infoPagination = $paginator->generate($Gamme, 8, $post, $this->renderer);


        return $this->renderer->render('@ajax-liste/listeGamme', [
            'ListeGamme' => $Gamme,
            'infoPagination' => $infoPagination,
            'post' => $post,
        ]);
    }
    public function societeUtilisateurAutoriseAction(): string
    {
        $post = $this->request->getParsedBody();



        $societe = new \Modules\Ajax\Repository\Listes($this->pdo);
        $societe = $societe->codeSteUtilisateur($post);

        $paginator = new Paginator();
        $infoPagination = $paginator->generate($societe, 8, $post, $this->renderer);


        return $this->renderer->render('@ajax-liste/listeSocieteUtilisateur', [
            'societeUtilisateurs' => $societe,
            'infoPagination' => $infoPagination,
            'post' => $post
        ]);
    }

    public function centreEmetteurUtilisateurAutoriseAction(): string
    {
        $post = $this->request->getParsedBody();



        $centreEmetteur = new \Modules\Ajax\Repository\Listes($this->pdo);
        $centreEmetteur = $centreEmetteur->centreEmetteurUtilisateur($post);

        $paginator = new Paginator();
        $infoPagination = $paginator->generate($centreEmetteur, 8, $post, $this->renderer);


        return $this->renderer->render('@ajax-liste/listeEmetteurUtilisateur', [
            'centreEmetteurs' => $centreEmetteur,
            'infoPagination' => $infoPagination,
            'post' => $post
        ]);
    }
    public function centreLivraisonUtilisateurAutoriseAction(): string
    {
        $post = $this->request->getParsedBody();



        $centreLivraison = new \Modules\Ajax\Repository\Listes($this->pdo);
        $centreLivraison = $centreLivraison->centreLivraisonUtilisateur($post);

        $paginator = new Paginator();
        $infoPagination = $paginator->generate($centreLivraison, 8, $post, $this->renderer);


        return $this->renderer->render('@ajax-liste/listeLivraisonUtilisateur', [
            'centreLivraisons' => $centreLivraison,
            'infoPagination' => $infoPagination,
            'post' => $post
        ]);
    }
    public function sectionImpuUtilisateurAutoriseAction(): string
    {
        $post = $this->request->getParsedBody();



        $sectionImpu = new \Modules\Ajax\Repository\Listes($this->pdo);
        $sectionImpu = $sectionImpu->sectionImputationUtilisateur($post);

        $paginator = new Paginator();
        $infoPagination = $paginator->generate($sectionImpu, 8, $post, $this->renderer);


        return $this->renderer->render('@ajax-liste/listeSectionImputationUtilisateur', [
            'sectionImputations' => $sectionImpu,
            'infoPagination' => $infoPagination,
            'post' => $post
        ]);
    }
    public function codeCompUtilisateurAutoriseAction(): string
    {
        $post = $this->request->getParsedBody();

        $codeComplementaire = new \Modules\Ajax\Repository\Listes($this->pdo);
        $codeComplementaire = $codeComplementaire->codeCompletementaireUtilisateur($post);

        $paginator = new Paginator();
        $infoPagination = $paginator->generate($codeComplementaire, 8, $post, $this->renderer);


        return $this->renderer->render('@ajax-liste/listeCodeComplementaireUtilisateur', [
            'codeComplementaires' => $codeComplementaire,
            'infoPagination' => $infoPagination,
            'post' => $post
        ]);
    }

    public function sousCompteAnaUtilisateurAutoriseAction(): string
    {
        $post = $this->request->getParsedBody();



        $sousCompte = new \Modules\Ajax\Repository\Listes($this->pdo);
        $sousCompte = $sousCompte->sousCompteAnalyseUtilisateur($post);

        $paginator = new Paginator();


        $infoPagination = $paginator->generate($sousCompte, 8, $post, $this->renderer);


        return $this->renderer->render('@ajax-liste/listeSousCompteAnaUtilisateur', [
            'sousCompteAnas' => $sousCompte,
            'infoPagination' => $infoPagination,
            'post' => $post
        ]);
    }
    public function centreAnalyseUtilisateurAutoriseAction(): string
    {
        $post = $this->request->getParsedBody();



        $centreAna = new \Modules\Ajax\Repository\Listes($this->pdo);
        $centreAna = $centreAna->centreAnalyseUtilisateur($post);


        $paginator = new Paginator();
        $infoPagination = $paginator->generate($centreAna, 8, $post, $this->renderer);


        return $this->renderer->render('@ajax-liste/listeCentreAnaUtilisateur', [
            'centreAnas' => $centreAna,
            'infoPagination' => $infoPagination,
            'post' => $post
        ]);
    }
    public function multiSocieteUtilisateurAutoriseAction(): string
    {
        $post = $this->request->getParsedBody();



        $multiSoc = new \Modules\Ajax\Repository\Listes($this->pdo);
        $multiSoc = $multiSoc->multiSocieteUtilisateur($post);

        $paginator = new Paginator();
        $infoPagination = $paginator->generate($multiSoc, 8, $post, $this->renderer);


        return $this->renderer->render('@ajax-liste/listeMultiSocUtilisateur', [
            'multiSocs' => $multiSoc,
            'infoPagination' => $infoPagination,
            'post' => $post
        ]);
    }

    public function familleAction(): string
    {
        $post = $this->request->getParsedBody();

        $entity = new listes($this->pdo);
        $entity = $entity->famille($post);

        $paginator = new Paginator();
        $infoPagination = $paginator->generate($entity, 8, $post, $this->renderer);

        return $this->renderer->render('@ajax-liste/listeFamille', [
            'entity' => $entity,
            'infoPagination' => $infoPagination,
            'post' => $post
        ]);
    }

    public function equivArtAction(): string
    {
        $numCleq = $this->request->getAttribute('numCleq');
        $codeFou = $this->request->getAttribute('codeFou');
        $post = $this->request->getParsedBody();

        $entity = new listes($this->pdo);
        $entity = $entity->equivArt($numCleq, $codeFou, $post);

        $commandeEntity = new GareDeTriage($this->pdo);
        foreach ($entity as &$val) {
            $val['PRIX_FRS'] = $commandeEntity->getBestPrixArtFrs('', $val['CODE_ART'], '0', ($post['societe'] ?? ''), ($post['CENTREL'] ?? ''), ($post['CENTREE'] ?? ''))['pu_remise'];
        }

        $paginator = new Paginator();
        $infoPagination = $paginator->generate($entity, 8, $post, $this->renderer);

        return $this->renderer->render('@ajax-liste/listeEquivArt', [
            'entity' => $entity,
            'infoPagination' => $infoPagination,
            'post' => $post,
            'numCleq' => $numCleq,
            'codeFou' => $codeFou,
        ]);
    }

    public function grpfouAction(): string
    {
        $post = $this->request->getParsedBody();

        $entity = new Grpfou($this->pdo);
        $entity = $entity->FetchAll([], $post);

        $paginator = new Paginator();
        $infoPagination = $paginator->generate($entity, 8, $post, $this->renderer);

        return $this->renderer->render('@ajax-liste/listeGrpfou', [
            'entity' => $entity,
            'infoPagination' => $infoPagination,
            'post' => $post
        ]);
    }

    public function ssItestoAction(): string
    {
        $post = $this->request->getParsedBody();

        $listes = new Listes($this->pdo);
        $listes = $listes->siteStock($post);

        $paginator = new Paginator();
        $infoPagination = $paginator->generate($listes, 8, $post, $this->renderer);

        return $this->renderer->render('@ajax-liste/listeSsItesto', [
            'listes' => $listes,
            'infoPagination' => $infoPagination,
            'post' => $post
        ]);
    }

    public function sitestoAction(): string
    {
        $post = $this->request->getParsedBody();

        $listes = new \Modules\Ajax\Repository\Listes($this->pdo);
        $listes = $listes->siteStockAlone($post);

        $paginator = new Paginator();
        $infoPagination = $paginator->generate($listes, 8, $post, $this->renderer);

        return $this->renderer->render('@ajax-liste/listeSsItesto', [
            'listes' => $listes,
            'infoPagination' => $infoPagination,
            'post' => $post
        ]);
    }

    public function dccEntetAction(): string
    {
        $post = $this->request->getParsedBody();

        $entity = new DccEntet($this->pdo);
        $listes = $entity->FetchAll([], $post);

        $paginator = new Paginator();
        $infoPagination = $paginator->generate($listes, 8, $post, $this->renderer);

        return $this->renderer->render('@ajax-liste/listeDcc', [
            'listes' => $listes,
            'infoPagination' => $infoPagination,
            'post' => $post
        ]);
    }


    public function typeDocAction(): string
    {
        $post = $this->request->getParsedBody();

        if (empty($post['filter_TYPE']) && ($post['filter_TYPE'] ?? '') !== '') {
            $post['valide'] = 'on';
        }

        $listes = new \Modules\Ajax\Repository\Listes($this->pdo);
        $entity = $listes->listeTypeDoc($post);

        $paginator = new Paginator();
        $infoPagination = $paginator->generate($entity, 8, $post, $this->renderer);

        return $this->renderer->render('@ajax-liste/listeTypeDoc', [
            'entity' => $entity,
            'infoPagination' => $infoPagination,
            'post' => $post
        ]);
    }

    public function unitesAction(): string
    {
        $post = $this->request->getParsedBody();

        $entity = new \Modules\Ajax\Repository\Listes($this->pdo);
        $entity = $entity->listeUnite($post);

        $paginator = new Paginator();
        $infoPagination = $paginator->generate($entity, 8, $post, $this->renderer);

        return $this->renderer->render('@ajax-liste/listeUnites', [
            'entity' => $entity,
            'infoPagination' => $infoPagination,
            'post' => $post
        ]);
    }

    public function sscptanaAction(): string
    {
        $post = $this->request->getParsedBody();

        $scaSecto = Roles::droit($this->pdo, 'SCASECTO', 'PARAMSTE');

        if (!$scaSecto) {
            unset($post['CODE_STE']);
            unset($post['filter_egal_CODE_STE']);
        }

        $entity = new Sscptana($this->pdo);
        $entity = $entity->FetchAll([], $post);

        $paginator = new Paginator();
        $infoPagination = $paginator->generate($entity, 8, $post, $this->renderer);

        return $this->renderer->render('@ajax-liste/listeSscptana', [
            'entity' => $entity,
            'infoPagination' => $infoPagination,
            'post' => $post,
            'scaSecto' => $scaSecto,
        ]);
    }

    public function directioAction(): string
    {
        $post = $this->request->getParsedBody();

        $liste = new \Modules\Ajax\Repository\Listes($this->pdo);
        $directio = $liste->Directio($post);

        $paginator = new Paginator();
        $infoPagination = $paginator->generate($directio, 8, $post, $this->renderer);

        return $this->renderer->render('@ajax-liste/listeDirectio', [
            'directions' => $directio,
            'infoPagination' => $infoPagination,
            'post' => $post
        ]);
    }

    public function natanaAction(): string
    {
        $post = $this->request->getParsedBody();

        $liste = new \Modules\Ajax\Repository\Listes($this->pdo);
        $natanas = $liste->Natana($post);

        $paginator = new Paginator();
        $infoPagination = $paginator->generate($natanas, 8, $post, $this->renderer);

        return $this->renderer->render('@ajax-liste/listeNatana', [
            'natanas' => $natanas,
            'infoPagination' => $infoPagination,
            'post' => $post
        ]);
    }

    public function centranaAction(): string
    {
        $post = $this->request->getParsedBody();

        $liste = new \Modules\Ajax\Repository\Listes($this->pdo);
        $centranas = $liste->Centrana($post);

        $paginator = new Paginator();
        $infoPagination = $paginator->generate($centranas, 8, $post, $this->renderer);

        return $this->renderer->render('@ajax-liste/listeCentrana', [
            'centranas' => $centranas,
            'infoPagination' => $infoPagination,
            'post' => $post
        ]);
    }

    public function uoAction(): string
    {
        $post = $this->request->getParsedBody();

        $entity = new UO($this->pdo);
        $entity = $entity->FetchAll([], $post);

        $paginator = new Paginator();
        $infoPagination = $paginator->generate($entity, 8, $post, $this->renderer);


        return $this->renderer->render('@ajax-liste/listeUo', [
            'entity' => $entity,
            'infoPagination' => $infoPagination,
            'post' => $post
        ]);
    }

    public function etatStatAction(): string
    {
        $post = $this->request->getParsedBody();

        $liste = new \Modules\Ajax\Repository\Listes($this->pdo);
        $entity = $liste->etatStat($post);

        $paginator = new Paginator();
        $infoPagination = $paginator->generate($entity, 8, $post, $this->renderer);

        return $this->renderer->render('@ajax-liste/ListeEtatStat', [
            'entity' => $entity,
            'infoPagination' => $infoPagination,
            'post' => $post
        ]);
    }

    public function groupeSignataireAction(): string
    {
        $post = $this->request->getParsedBody();


        $liste = new \Modules\Ajax\Repository\Signataires($this->pdo);
        $groupeSigna = $liste->signataireREFGroupe();

        $paginator = new Paginator();
        $infoPagination = $paginator->generate($groupeSigna, 8, $post, $this->renderer);

        return $this->renderer->render('@ajax-liste/listeGroupeSignat', [
            'infoPagination' => $infoPagination,
            'groupeSigna' => $groupeSigna,
            'post' => $post
        ]);
    }

    public function periodesAction(): string
    {

        $post = $this->request->getParsedBody();
        $post['tri_DATE_FIN'] = $post['tri_DATE_FIN'] ?? 'desc';

        $entity = new Periodes($this->pdo);
        $entity = $entity->FetchAll([], $post);


        $paginator = new Paginator();
        $infoPagination = $paginator->generate($entity, 8, $post, $this->renderer);

        return $this->renderer->render('@ajax-liste/listePeriodes', [
            'entity' => $entity,
            'infoPagination' => $infoPagination,
            'post' => $post
        ]);
    }

    public function utilisateursOxalinkAction(): string
    {

        $post = $this->request->getParsedBody();

        $entity = new OxalinkUser($this->pdo);
        $utilisateurs = $entity->FetchAll([], $post);


        $paginator = new Paginator();
        $infoPagination = $paginator->generate($utilisateurs, 8, $post, $this->renderer);

        return $this->renderer->render('@ajax-liste/listeUtilisateursOxalink', [
            'utilisateurs' => $utilisateurs,
            'infoPagination' => $infoPagination,
            'post' => $post,
            'pathUser' => 'utilisateursOxalink',
        ]);
    }

    public function tsDonAction(): string
    {
        $typeDico = $this->request->getAttribute('typeDico');
        $societe = $this->request->getAttribute('societe') ?? '';
        $post = $this->request->getParsedBody();

        $csType = new CsTypes($this->pdo);
        $infoCSType = $csType->find(['TYPE' => $typeDico]);

        if ($societe != '') {
            $post['filter_egal_COD_STE'] = $societe;
        }
        $paginator = new \Helpers\Pagination\PaginatorGestion();
        $infoPagination = $paginator->generate(8, 'CS.CODEDICO', 'asc');
        
        $entity = new ChampSupp($this->pdo);
        $entity = $entity->generateCSSelect($typeDico, $post);

        $infoPagination = \Helpers\Pagination\PaginatorGestion::getInfoPagination();

        if ($societe != '') {
            $path = $this->router->generateUri('Ajax.liste.tsDon', ['typeDico' => $typeDico, 'societe' => $societe]);
        } else {
            $path = $this->router->generateUri('Ajax.liste.tsDon', ['typeDico' => $typeDico]);
        }

        return $this->renderer->render('@ajax-liste/listeTS_DON', [
            'entity' => $entity,
            'infoPagination' => $infoPagination,
            'post' => $post,
            'typeDico' => $typeDico,
            'societe' => $societe,
            'path' => $path,
            'infoCSType' => $infoCSType,
        ]);
    }

    public function clausierAction(): string
    {
        $post = $this->request->getParsedBody();

        $entity = new Listes($this->pdo);
        $listeEntity = $entity->listeCLausier($post);

        $paginator = new Paginator();
        $infoPagination = $paginator->generate($listeEntity, 5, $post, $this->renderer);

        return $this->renderer->render('@ajax-liste/listeClausier', [
            'entity' => $listeEntity,
            'infoPagination' => $infoPagination,
            'post' => $post,
            'path' => $this->router->generateUri('Ajax.liste.clausier'),
        ]);
    }

    /**
     * @return string
     */
    public function docCatAction(): string
    {
        $post = $this->request->getParsedBody();

        $entity = new Listes($this->pdo);
        $listeEntity = $entity->listeDocCat($post);

        $paginator = new Paginator();
        $infoPagination = $paginator->generate($listeEntity, 5, $post, $this->renderer);

        return $this->renderer->render('@ajax-liste/listeDocCat', [
            'listeEntity'       => $listeEntity,
            'infoPagination'    => $infoPagination,
            'post'              => $post,
        ]);
    }
}
