<?php

namespace Modules\Ajax\Controller;

use Entity\Model\AoExcEnte;
use Entity\Model\CFormats;
use Entity\Model\DaModel;
use Entity\Model\Hastutil;
use Entity\Model\Paramnum;
use Entity\Model\ProfilTva;
use Entity\Model\Rayon;
use Exception;
use Helpers\Log\LogSysteme;
use Helpers\Outil\ZoomHelper;
use Helpers\QueryBuilder\QueryBuilder;
use Helpers\Session\ParseBase1;
use Modules\EtatStatistiques\Repository\EtatStatTypeRepo;
use Modules\GlobalApplication\Repository\LicenceOxalys;
use Modules\GlobalApplication\Repository\Societe;
use Modules\Stock\Enum\EmptyEnum;
use Modules\Stock\Repository\DemandeAchatRepo;
use Modules\Stock\Service\ListManagerService;
use Modules\Tables\MenuContextuel\CentresContextuel;
use Modules\Tables\MenuContextuel\EvenementTPContextuel;
use Skeleton\Controller\Controller;
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\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(?QueryBuilder $qb = null): string
    {
        $entity = $this->request->getAttribute('entity');
        $post = $this->request->getParsedBody();

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

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

        (new PaginatorGestion())->generate(8, $primaryKey);
        
        $listEntity = $entityGenerator->findAll(
            null,
            [],
            [
                'filter_' . $primaryKey => $post['filter_' . $primaryKey] ?? '',
                'filter_' . $libelleKey => $post['filter_' . $libelleKey] ?? '',

                'tri_' . $primaryKey => $post['tri_' . $primaryKey] ?? '',
                'tri_' . $libelleKey => $post['tri_' . $libelleKey] ?? '',
                'page' => $post['page'] ?? null,
            ]
        );

        return $this->renderer->render('@Ajax/liste/listeEntity', [
            'listEntity' => $listEntity,
            'infoPagination' => PaginatorGestion::getInfoPagination(),
            'post' => $post,
            'entity' => $entity,
            'primaryKey' => $primaryKey,
            'libelleKey' => $libelleKey,
        ]);
    }
    
    public function etatStatThemeAction() :string
    {
        return $this->simpleEntityList();
    }

    public function hastutilAction() :string
    {
        return $this->simpleEntityList();
    }

    public function etatGroupeAction() :string
    {
        return $this->simpleEntityList();
    }

    public function factureAction() :string
    {
        return $this->simpleEntityList();
    }

    private function simpleEntityList() :string
    {
        $class = ZoomHelper::getEntityFromPath($this->router->getNameRoute());
        if ($class == null) {
            throw new \Exception('No entity associated to "'. $this->router->getNameRoute() .'"');
        }
        // TOOD : add possibility to have constant $post filter
        return $this->entityListAction(new $class($this->pdo));
    }

    private function getQueryBuilder(string $s) :?QueryBuilder
    {
        // TODO: replace with 'route to entity' resolution of ZoomHelper
        switch ($s) {
            case 'ProfilTva':
                return new ProfilTva($this->pdo);
            case 'Tiers':
                return new Tiers($this->pdo);
            case 'DaModel':
                return new DaModel($this->pdo);
            case 'CFormats':
                return new CFormats($this->pdo);
            default:
        }
        return null;
    }

    public function etatStatFiltreTypeAction() :string
    {
        $entity = $this->request->getAttribute('entity');
        $post = $this->request->getParsedBody();

        if (empty($post['TYPE_FILTRE'])) {
            LogSysteme::prefixErrorLog('Missing TYPE_FILTRE');
        }

        (new PaginatorGestion())->generate(8, 'CODE_FILTRE');
        $listEntity = (new EtatStatTypeRepo($this->pdo))
            ->listFiltreType($post + ['tri_LIBELLE' => 'ASC']);

        return $this->renderer->render('@Ajax/liste/listeEntity', [
            'listEntity' => $listEntity,
            'infoPagination' => PaginatorGestion::getInfoPagination(),
            'post' => $post,
            'entity' => $entity,
            'primaryKey' => 'CODE_FILTRE',
            'libelleKey' => 'LIBELLE',
            // 'listFieldAutofill' => []
        ]);
    }

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

        (new PaginatorGestion())->generate(8);
        $listeEntity = (new \Entity\Model\Doa($this->pdo))->findAll(null, [], $post);

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

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

        (new PaginatorGestion())->generate(8);
        $liste = (new Listes($this->pdo))->listeCampNotex($post);

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

    public function aoFormatExcelAction(): string
    {
        $post = $this->request->getParsedBody();
        
        (new PaginatorGestion())->generate(8);
        $listEntity = (new AoExcEnte($this->pdo))->findAll(null, [], $post);

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

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

        (new PaginatorGestion())->generate(8);
        $listeEntity = (new GestionConsultation($this->pdo))->listeConsultation($post);

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

    public function typeDeMarcheAction(): string
    {

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

        (new PaginatorGestion())->generate(8);
        $typeMarche = (new \Entity\Model\TypeDeMarche($this->pdo))->findALl(null, [], $post);

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

    public function commandeAction(): string
    {

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

        (new PaginatorGestion())->generate(8);
        $commande = (new CaEntet($this->pdo))->findAll(null, [], $post);

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

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

        (new PaginatorGestion())->generate(8);
        $entity = (new Langues($this->pdo))->findAll(null, [], $post);

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

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

        (new PaginatorGestion())->generate(8);
        $entity = (new Suicadat($this->pdo))->findAll(null, [], $post);

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

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

        (new PaginatorGestion())->generate(8);
        $entity = (new Douanes($this->pdo))->findAll(null, [], $post);

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

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

        (new PaginatorGestion())->generate(8);
        $cQualite = (new Cqualite($this->pdo))->findAll(null, [], $post);

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

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

        (new PaginatorGestion())->generate(8);
        $messstan = (new Messstan($this->pdo))->findAll(null, [], $post);

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

    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();

        (new PaginatorGestion())->generate(8);
        $br = (new BrLigne($this->pdo))->findAll(null, [], $post);

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

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

        (new PaginatorGestion())->generate(8);
        $fonction = (new Fcontfrn($this->pdo))->findAll(null, [], $post);

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

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

        (new PaginatorGestion())->generate(8);
        $fonction = (new FoncUsr($this->pdo))->findAll(null, [], $post);

        return $this->renderer->render('@ajax-liste/listeFonctionUser', [
            'entity' => $fonction,
            'infoPagination' => PaginatorGestion::getInfoPagination(),
            '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';
        }

        $liste = new Listes($this->pdo);
        if ($type == 'userOxalink') {
            (new PaginatorGestion())->generate(8);
            $listeUser = $liste->utilisateursOxalink($post);
            $infoPagination = PaginatorGestion::getInfoPagination();
            $nbrUserOxalink = PaginatorGestion::getNbrArticle();

            (new PaginatorGestion())->generate(1); // Note : here the Paginator is used to make a count
            $liste->utilisateurListe([]);
            $nbrUser = PaginatorGestion::getNbrArticle();
        } else {
            if (($post['oxalink'] ?? 0) == '1'
                && (new LicenceOxalys($this->pdo))->hasOxalink()
            ) {
                (new PaginatorGestion())->generate(1); // Note : here the Paginator is used to make a count
                $liste->utilisateursOxalink([]);
                $nbrUserOxalink = PaginatorGestion::getNbrArticle();
            }

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

            (new PaginatorGestion())->generate(8);
            $listeUser = $liste->utilisateurListe($post);
            $infoPagination = PaginatorGestion::getInfoPagination();
            $nbrUser = PaginatorGestion::getNbrArticle();
        }
        
        if (($post['litige_user_type'] ?? '' != '') || ($post['litige']??'') == 'true') {
            $type = 'respLitige';
        }

        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 delegatairePrefAction(): string
    {
        $post = $this->request->getParsedBody();

        (new PaginatorGestion())->generate(8);
        $listeUser = (new Listes($this->pdo))->listDeleg($post);
        
        return $this->renderer->render('@ajax-liste/listeUtilisateurSimple', [
            'utilisateurs' => $listeUser,
            'infoPagination' => PaginatorGestion::getInfoPagination(),
            'post' => $post,
            'pathUser' => 'Ajax.liste.delegatairePref',
            'listParam' => ['CODE_STE', ''],
        ]);
    }

    public function acheteurUserAction(): string
    {
        $post = $this->request->getParsedBody();
        $post['ACHETEUR'] = SQL::setBoolSql(1);
        unset($post['filter_ACHETEUR']);
        return $this->utilisateurListe($post);
    }

    public function demandeurAction(): string
    {
        $post = $this->request->getParsedBody();
        $post['DEMAND'] = SQL::setBoolSql(1);
        $post['CODE_STE'] = $post['filter_egal_CODE_STE'];
        return $this->utilisateurListe($post);
    }

    public function sigFactAction(): string
    {
        $post = $this->request->getParsedBody();
        $post['SIG_BAP'] = SQL::setBoolSql(1);
        $post['VALIDE'] = SQL::setBoolSql(1);
        return $this->utilisateurListe($post);
    }

    /**
     * @param array<mixed> $post
     */
    private function utilisateurListe(array $post) :string
    {
        (new PaginatorGestion())->generate(8);
        $hastutil = (new Listes($this->pdo))->utilisateurListe($post);

        return $this->renderer->render('@ajax-liste/listeUtilisateur', [
            'utilisateurs' => $hastutil,
            'infoPagination' => PaginatorGestion::getInfoPagination(),
            'post' => $post,
            'pathUser' => $this->router->getNameRoute(),
        ]);
    }

    public function sigBAPAction():string
    {
        return $this->sigFactAction();
    }

    public function sigCdeAction(): string
    {
        $post = $this->request->getParsedBody();
        $post['SIG_CDE'] = SQL::setBoolSql(1);
        $post['VALIDE'] = SQL::setBoolSql(1);
        return $this->utilisateurListe($post);
    }

    public function sigDAAction(): string
    {
        $post = $this->request->getParsedBody();
        $post['SIG_DA'] = SQL::setBoolSql(1);
        $post['VALIDE'] = SQL::setBoolSql(1);

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

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

    public function societeAction(): string
    {
        $post = $this->request->getParsedBody();
        $action = $this->request->getAttribute('action');

        if (!isset($post['tri_CODE_STE'])) {
            $post['tri_CODE_STE'] = 'asc';
        }

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

        $infoPagination = PaginatorGestion::getInfoPagination();

        // 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);
        }

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

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

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

        (new PaginatorGestion())->generate(8);
        $societes = (new Listes($this->pdo))->findGroupedCompanies($post);

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

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

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

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

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

        (new PaginatorGestion())->generate(8);
        $conditionDePaiements = (new Listes($this->pdo))->ConditionPaiement($post);

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

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

        (new PaginatorGestion())->generate(8);
        $modeDePaiements = (new Listes($this->pdo))->modePaiement($post);

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


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

        (new PaginatorGestion())->generate(8);
        $modeDeLivraisons = (new Listes($this->pdo))->modeLivraison($post);

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

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

        $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'];
        }

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

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

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

            $post['activeZone'] = $rechercheRepo->zoneGeoActive($centre)['active']? 1:0;
            $post['centre'] = $centre;
        }

        $post['typeActif'] = $type;
        $afficheTouslesfournisseur = true;
        $countSousFamille = 0;
        $countArtHaplus = 0;
        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';
            }
        }

        $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['advancedPopup'] ?? false)) {
            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;
                }
            }
        } elseif ($post['frsPanier']??'' ==1) {
            $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 ($type == '') {
            if (($post['code_sous_famille'] ?? '') != '') {
                $type = $post['typeActif'] = 'sousFamille';
            }
            if (($post['code_art_haplus'] ?? '') != '') {
                $type = $post['typeActif'] = 'article';
            }
        }


        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->getListeTrad([$post['code_sous_famille']])[0];
        }

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


        if (!(isset($post['centre']) && $post['centre'] != '')) {
            $post['centre'] = $_SESSION['Session_CodeCtrEmetteur'];
        }

        $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 = [];
        }

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

    public function fournisseurSansArticlesSansCommandeAction(): 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 Listes($this->pdo);

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

            $listeZoneGeoCentre = $liste->listeZoneGeoCentre($centre);

            $post['activeZone'] = $rechercheRepo->zoneGeoActive($centre)['active'];
            $post['centre'] = $centre;
        }

        $post['typeActif'] = $type;
        $afficheTouslesfournisseur = true;
        $countSousFamille = 0;
        $countArtHaplus = 0;
        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';
            }
        }

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

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

        $infoPagination = PaginatorGestion::getInfoPagination();
        /** @phpstan-ignore-next-line */

        if (($post['advancedPopup'] ?? false)) {
            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->getListeTrad([$post['code_sous_famille']])[0];
            }
        }

        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 = [];
        }

        if (!(isset($post['centre']) && $post['centre'] != '')) {
            $post['centre'] = $_SESSION['Session_CodeCtrEmetteur'];
        }

        $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.fournisseurSansArticlesSansCommande',
            'listeColonne' => $listeColonne,
            'labelValide' => $labelValide,
            'codeSousFamille' => $post['code_sous_famille'] ?? '',
            'codeArtHaplus' => $post['code_art_haplus'] ?? '',
            'type' => $type == ''? null:$type,
            'motsClefs' => $tabmotsClefs,
            'shortLists' => $tabTypeFourniss,
            'afficheTouslesfournisseur' => $afficheTouslesfournisseur,
            'nbrArticle' => $countArtHaplus,
            'nbrSousFamille' => $countSousFamille,
            'nbrFournisseurs' => $nbrFournisseur,
            'libelleArticle' => $article['DESIGN'] ?? '',
            'listePays' => $listePays,
            'libelleSfFamille' => $sousFamille['DESIGNAT'] ?? '',
        ]);
    }

    public function fournisseurAvecArticlesSansCommandeAction(): 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 Listes($this->pdo);

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

            $listeZoneGeoCentre = $liste->listeZoneGeoCentre($centre);

            $post['activeZone'] = $rechercheRepo->zoneGeoActive($centre)['active'];
            $post['centre'] = $centre;
        }

        $post['typeActif'] = $type;
        $afficheTouslesfournisseur = true;
        $countSousFamille = 0;
        $countArtHaplus = 0;
        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';
            }
        }

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

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

        $infoPagination = PaginatorGestion::getInfoPagination();
        /** @phpstan-ignore-next-line */
        
        if ($post['advancedPopup'] ?? false) {
            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->getListeTrad([$post['code_sous_famille']])[0];
            }
        }

        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 = [];
        }


        if (!(isset($post['centre']) && $post['centre'] != '')) {
            $post['centre'] = $_SESSION['Session_CodeCtrEmetteur'];
        }

        

        $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.fournisseurAvecArticlesSansCommande',
            'listeColonne' => $listeColonne,
            'labelValide' => $labelValide,
            'codeSousFamille' => $post['code_sous_famille'] ?? '',
            'codeArtHaplus' => $post['code_art_haplus'] ?? '',
            'type' => $type == ''? null:$type,
            'motsClefs' => $tabmotsClefs,
            'shortLists' => $tabTypeFourniss,
            'afficheTouslesfournisseur' => $afficheTouslesfournisseur,
            '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;

        (new PaginatorGestion())->generate(8);
        $contactsFournisseur = (new Listes($this->pdo))->contactsFournisseur($post);

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

        (new PaginatorGestion())->generate(8);
        $contactsFournisseur = (new Listes($this->pdo))->contactsFournisseur($post);

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

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

        (new PaginatorGestion())->generate(8);
        $listeAdresse = (new Listes($this->pdo))->adresseFournisseur($post);

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

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

        (new PaginatorGestion())->generate(8);
        $listeAdresse = (new Listes($this->pdo))->adresseCentre($post);

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

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

        (new PaginatorGestion())->generate(8);
        $contactsFournisseur = (new \Entity\Model\Contfour($this->pdo))->findAll(null, [], $post);

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

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

        (new PaginatorGestion())->generate(8);
        $contact = (new \Entity\Model\CtcCtr($this->pdo))->findAll(null, [], $post);

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

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

        (new PaginatorGestion())->generate(8);
        $devises = (new Listes($this->pdo))->Devise($post);

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


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

        (new PaginatorGestion())->generate(8);
        $caEntet = (new Listes($this->pdo))->CaEntet($post);
        $trad = $this->getTranslationService();

        $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") && !Roles::droitsUtilisateur($this->pdo, 'HA_CA_VIPX') && !Roles::droitsUtilisateur($this->pdo, 'HA_BR_PX'))
                ||
                ((isset($post['sourcePrincipale']) && $post['sourcePrincipale'] != "BR") && !Roles::droitsUtilisateur($this->pdo, 'HA_CA_VIPX'))
            )
        ) {
            $noprice = 1;
        }

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


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

        (new PaginatorGestion())->generate(8);
        $ordonances = (new \Entity\Model\Ordonanc($this->pdo))->findAll(null, [], $post);

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

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

        (new PaginatorGestion())->generate(8);
        $Regroup = new \Entity\Model\Regroupement($this->pdo);
        $Regroup = $Regroup->findAll(null, [], $post);

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

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

        (new PaginatorGestion())->generate(8);
        $listeFrs = (new Listes($this->pdo))->listeFrsAndGrpFou($post);

        return $this->renderer->render('@ajax-liste/listeFrsAndGrpFou', [
            'entity' => $listeFrs,
            'infoPagination' => PaginatorGestion::getInfoPagination(),
            'post' => $post
        ]);
    }


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

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

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

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

        $devise_base = sql::parametr($this->pdo, 'HADEVSTK');

        $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 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();
        $paginator->generate(8, 'ID_CDC', 'ASC');
        $liste = new 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();
        $paginator->generate(8, 'ID_SCA', 'ASC');

        $liste = new 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;
        }

        (new PaginatorGestion())->generate(8);
        $centre = (new \Entity\Model\Centre($this->pdo))->findAll(null, [], $post);

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

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

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

        (new PaginatorGestion())->generate(8);
        $centre = (new Listes($this->pdo))->centreEmetteur($post);

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

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

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

        (new PaginatorGestion())->generate(8);
        $centre = (new Listes($this->pdo))->centreLivraison($post);

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

        return $this->renderer->render('@ajax-liste/listeCentre', [
            'centres' => $centre,
            'infoPagination' => PaginatorGestion::getInfoPagination(),
            '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();

        (new PaginatorGestion())->generate(8);
        $centre = (new Listes($this->pdo))->centreEmetteur($post);

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

        return $this->renderer->render('@ajax-liste/listeCentre', [
            'centres' => $centre,
            'infoPagination' => PaginatorGestion::getInfoPagination(),
            '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');

        (new PaginatorGestion())->generate(8);
        $liste = new 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);
        }

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

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

        (new PaginatorGestion())->generate(8);
        $centre = (new Listes($this->pdo))->centreLivraison($post);

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


    //______________FIN_________________



    // DEBUT IMPRIMER ACCORD DE CADRE ::

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

        $liste = new 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 centreLivraisonImpressionAction(): string
    {
        $post = $this->request->getParsedBody();

        (new PaginatorGestion())->generate(8);
        $centreLiv = (new Listes($this->pdo))->centreLivraisonImpression($post);

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


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

        (new PaginatorGestion())->generate(8);

        $centreEmetteur = (new Listes($this->pdo))->centreEmetteurImpression($post);

        return $this->renderer->render('@ajax-liste/listeEmetteurImpression', [
            'centreEm' => $centreEmetteur,
            'infoPagination' => PaginatorGestion::getInfoPagination(),
            'post' => $post
        ]);
    }

    public function societeImpressionAction(): string
    {

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

        $liste = new 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
        ]);
    }

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

        (new PaginatorGestion())->generate(8);
        $typeAchat = (new Listes($this->pdo))->typeAchat($post);

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

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

        (new PaginatorGestion())->generate(8);
        $motClef = (new MotClef($this->pdo))->fetchAll([], $post);

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

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

        (new PaginatorGestion())->generate(8);
        $entity = (new DomaineCompetence($this->pdo))->findAll(null, [], $post);

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

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

        (new PaginatorGestion())->generate(8);
        $Pays = (new \Entity\Model\Country($this->pdo))->findAll(null, [], $post);

        return $this->renderer->render('@ajax-liste/listePays', [
            'listPays' => $Pays,
            'infoPagination' => PaginatorGestion::getInfoPagination(),
            '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;
            $post['tri_CODE_ART'] = 'asc';
        } else {
            Outils::isCheck($post['valide']);
            Outils::isCheck($post['GENRERIQUE']);
        }

        $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);
        }

        $infoPagination = PaginatorGestion::getInfoPagination();

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

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

        $paginator = new PaginatorGestion;
        $paginator->generate(12, 'CODE_ART');

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

        $items = (new Listes($this->pdo))->listeArticlesSiCdcSca($post);

        return $this->renderer->render('@ajax-liste/listeArticlesSiCdcSca', [
            'listeArticles' => $items,
            'infoPagination' => PaginatorGestion::getInfoPagination(),
            'post' => $post,
            'pathPopup' => 'Ajax.liste.articlesSiCdcSca',
        ]);
    }

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

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

        (new PaginatorGestion())->generate(8);
        $Articles = (new Listes($this->pdo))->listeArticles($post);

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

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

        (new PaginatorGestion())->generate(12, 'CODE_ART');

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

        $items = (new Listes($this->pdo))->listeArticlesFrsFaSfa($post);

        $infoPagination = PaginatorGestion::getInfoPagination();

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

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

        $post['tri_LIBELLE'] = 'asc';

        (new PaginatorGestion())->generate(8);
        $marches = (new Listes($this->pdo))->marches($post);

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

    public function accadreAction(): string
    {

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

        (new PaginatorGestion())->generate(8);
        $accadre = (new Listes($this->pdo))->AccordCadre($post);


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

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

        (new PaginatorGestion())->generate(8);
        $acheteurs = (new Listes($this->pdo))->acheteur($post);

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

    public function utilisateurSocieteAction(): string
    {
        $post = $this->request->getParsedBody();
        $post['email'] = isset($post['email']) && ($post['email'] == 'true' || $post['email'] == 1) ? true : false;

        (new PaginatorGestion())->generate(8);
        $utilisateurs = (new Listes($this->pdo))->utilisateurSociete($post);

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

    public function sousFamilleAction(): string
    {
        $post = $this->request->getParsedBody();
        
        (new PaginatorGestion())->generate(8);
        $sousFamilles = (new Listes($this->pdo))->sousFamille($post);

        return $this->renderer->render('@ajax-liste/listeSousFamille', [
            'sousFamilles' => $sousFamilles,
            'infoPagination' => PaginatorGestion::getInfoPagination(),
            '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();

        (new PaginatorGestion())->generate(8);
        $BceFexp = (new BceFexp($this->pdo))->findAll(null, [], $post);

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

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

        (new PaginatorGestion())->generate(8);
        $fabricant = (new Fabricant($this->pdo))->findAll(null, [], $post);

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

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

        (new PaginatorGestion())->generate(8);
        $Gamme = (new Gamme($this->pdo))->findAll(null, [], $post);

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

        (new PaginatorGestion())->generate(8);
        $societe = (new Listes($this->pdo))->codeSteUtilisateur($post);

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

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

        (new PaginatorGestion())->generate(8);
        $centreEmetteur = (new Listes($this->pdo))->centreEmetteurUtilisateur($post);

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

        (new PaginatorGestion())->generate(8);
        $centreLivraison = (new Listes($this->pdo))->centreLivraisonUtilisateur($post);

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

        (new PaginatorGestion())->generate(8);
        $sectionImpu = (new Listes($this->pdo))->sectionImputationUtilisateur($post);

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

        (new PaginatorGestion())->generate(8);
        $codeComplementaire = (new Listes($this->pdo))->codeCompletementaireUtilisateur($post);

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

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

        (new PaginatorGestion())->generate(8);
        $sousCompte = (new Listes($this->pdo))->sousCompteAnalyseUtilisateur($post);

        return $this->renderer->render('@ajax-liste/listeSousCompteAnaUtilisateur', [
            'sousCompteAnas' => $sousCompte,
            'infoPagination' => PaginatorGestion::getInfoPagination(),
            'post' => $post
        ]);
    }

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

        (new PaginatorGestion())->generate(8);
        $centreAna = new Listes($this->pdo);
        $centreAna = $centreAna->centreAnalyseUtilisateur($post);

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

        (new PaginatorGestion())->generate(8);
        $multiSoc = (new Hastutil($this->pdo))->findAll([
            'UTIMULTI' => 'T',
        ], [], $post);

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

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

        (new PaginatorGestion())->generate(8);
        $entity = (new Listes($this->pdo))->famille($post);

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

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

        (new PaginatorGestion())->generate(8);
        $entity = (new Listes($this->pdo))->equivArt($numCleq, $codeFou, $post);

        $infoPagination = PaginatorGestion::getInfoPagination();

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

        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();

        (new PaginatorGestion())->generate(8);
        $entity = (new Grpfou($this->pdo))->findAll(null, [], $post);

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

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

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

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

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

        (new PaginatorGestion())->generate(8);
        $listes = new Listes($this->pdo);
        $listes = $listes->siteStockAlone($post);

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

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

        (new PaginatorGestion())->generate(8);
        $entity = new DccEntet($this->pdo);
        $listes = $entity->findAll(null, [], $post);

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


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

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

        $listes = new 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 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
    {
        // TODO : factorize with scaAction ?
        $post = $this->request->getParsedBody();

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

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

        (new PaginatorGestion())->generate(8);
        $entity = new Sscptana($this->pdo);
        $entity = $entity->findAll(null, [], $post);

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

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

        (new PaginatorGestion())->generate(8);
        $liste = new Listes($this->pdo);
        $directio = $liste->Directio($post);

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

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

        (new PaginatorGestion())->generate(8);
        $liste = new Listes($this->pdo);
        $natanas = $liste->Natana($post);

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

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

        (new PaginatorGestion())->generate(8);
        $liste = new Listes($this->pdo);
        $centranas = $liste->Centrana($post);

        return $this->renderer->render('@ajax-liste/listeCentrana', [
            'centranas' => $centranas,
            'infoPagination' => PaginatorGestion::getInfoPagination(),
            '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();

        (new PaginatorGestion())->generate(8);
        $liste = new Listes($this->pdo);
        $entity = $liste->etatStat($post);

        return $this->renderer->render('@ajax-liste/listeEtatStat', [
            'entity' => $entity,
            'infoPagination' => PaginatorGestion::getInfoPagination(),
            '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';

        (new PaginatorGestion())->generate(8);
        $entity = (new Periodes($this->pdo))->findAll(null, [], $post);

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

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

        (new PaginatorGestion())->generate(8);
        $utilisateurs = (new OxalinkUser($this->pdo))->findAll(null, [], $post);

        return $this->renderer->render('@ajax-liste/listeUtilisateursOxalink', [
            'utilisateurs' => $utilisateurs,
            'infoPagination' => PaginatorGestion::getInfoPagination(),
            '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();
        $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,
        ]);
    }

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

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

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

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

    /**
     * @throws Exception
     */
    public function demandeAchatAction(): string
    {
        $post = $this->request->getParsedBody();
        $action = $this->request->getAttribute('action');

        (new PaginatorGestion())->generate(10, 'NO_DA');
        $demandesAchat = (new DemandeAchatRepo($this->pdo))->listDemandesAchat($post);
        $infoPagination = PaginatorGestion::getInfoPagination();

        return $this->renderer->render('@ajax-liste/listeDemandeAchat', [
            'demandesAchat'    => $demandesAchat,
            'infoPagination'   => $infoPagination,
            'post'             => $post,
            'pathUser'         => 'Ajax.liste.demandeAchat',
            'action'           => $action,
            'listeChoixStatut' => (new ListManagerService($this->getTranslationService()))->getChoixDemandeAchatStatutList()
        ]);
    }

    /**
     * @throws Exception
     */
    public function tiersDestinataireAction(): string
    {
        $post = $this->request->getParsedBody();
        (new PaginatorGestion())->generate(10, 'CODE');
        $tiersDestinataires = (new Listes($this->pdo))->listeTiersDestinataires($post);
        $infoPagination = PaginatorGestion::getInfoPagination();

        return $this->renderer->render('@ajax-liste/listeTiersDestinataire', [
            'post' => $post,
            'infoPagination' => $infoPagination,
            'tiersDestinataires' => $tiersDestinataires,
            'emptyValue' => EmptyEnum::EMPTY_VALUE->value,
        ]);
    }

    /**
     * @throws Exception
     */
    public function tiersAction(): string
    {
        $post = $this->request->getParsedBody();

        (new PaginatorGestion())->generate(10, 'CODE');
        $tiers = (new Listes($this->pdo))->getListeTiers($post);
        $infoPagination = PaginatorGestion::getInfoPagination();

        return $this->renderer->render('@ajax-liste/listeTiers', [
            'tiers' => $tiers,
            'infoPagination' => $infoPagination,
            'post' => $post,
            'emptyValue' => EmptyEnum::EMPTY_VALUE->value
        ]);
    }

    /**
     * @throws Exception
     */
    public function siteStockAccessibleAction(): string
    {
        $post = $this->request->getParsedBody();

        (new PaginatorGestion())->generate(10, 'SITE');
        $sitesStocks = (new Listes($this->pdo))->listSitesStockAccessibles($post);
        $infoPagination = PaginatorGestion::getInfoPagination();

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

    /**
     * @throws Exception
     */
    public function stockLocalAction(): string
    {
        $post = $this->request->getParsedBody();

        $parameters = $post;
        if (array_key_exists('MULTILINGUE', $post)) {
            $post['filter_TA#point#DES_ART'] = $post['filter_DESIGN'];
            $parameters['filter_TA#point#DES_ART'] = $post['filter_DESIGN'];
            unset($parameters['filter_DESIGN']);
        } else {
            unset($post['filter_TA#point#DES_ART']);
            unset($parameters['filter_TA#point#DES_ART']);
        }
        if (array_key_exists('filter_CODE_ART', $post)) {
            $parameters['filter_STO#point#CODE_ART'] = $post['filter_CODE_ART'];
            unset($parameters['filter_CODE_ART']);
        }

        (new PaginatorGestion())->generate(10, 'CODE_ART');
        $listes = (new Listes($this->pdo))->listeStocksLocaux($parameters);
        $infoPagination = PaginatorGestion::getInfoPagination();

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

    /**
     * @throws Exception
     */
    public function demandesServicesAction(): string
    {
        $post = $this->request->getParsedBody();

        (new PaginatorGestion())->generate(10, 'NO_DS');
        $demandesServices = (new Listes($this->pdo))->listeDemandesServices($post);
        $infoPagination = PaginatorGestion::getInfoPagination();

        return $this->renderer->render('@ajax-liste/listeDemandesServices', [
            'post' => $post,
            'infoPagination' => $infoPagination,
            'demandesServices' => $demandesServices,
            'listeFiltreType' => (new ListManagerService($this->getTranslationService()))->getDemandeServiceTypesList()
        ]);
    }

    /**
     * @throws Exception
     */
    public function daModelsAction(): string
    {
        $post = $this->request->getParsedBody();

        (new PaginatorGestion())->generate(10, 'COD_MDLE');
        $liste = (new Listes($this->pdo))->listeDaModels($post);
        $infoPagination = PaginatorGestion::getInfoPagination();

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

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

        (new PaginatorGestion())->generate(10, 'NO_PR');
        $liste = (new Listes($this->pdo))->listePropositionsReappro($post);
        $infoPagination = PaginatorGestion::getInfoPagination();

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

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

        (new PaginatorGestion())->generate(10, 'NO_LOT');
        $stockLotsLocaux = (new Listes($this->pdo))->listeStockLotsLocaux($post);
        $infoPagination = PaginatorGestion::getInfoPagination();

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



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

        (new PaginatorGestion())->generate(10, 'CODE_SFA');
        $sousFamilles = (new Listes($this->pdo))->listeSousFamilles($post);
        $infoPagination = PaginatorGestion::getInfoPagination();

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

        (new PaginatorGestion())->generate(10, 'CODE_EVT');
        $tyevtstp = (new Listes($this->pdo))->listeTyevtstp($post);
        $infoPagination = PaginatorGestion::getInfoPagination();

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

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

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

        (new PaginatorGestion())->generate(10, 'CODE_ART');
        $articles = (new Listes($this->pdo))->listArticlesNotOnSite($post);
        $infoPagination = PaginatorGestion::getInfoPagination();

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

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

        (new PaginatorGestion())->generate(10, 'CODE');
        $srubcomps = (new Listes($this->pdo))->listSrubComps($post);
        $infoPagination = PaginatorGestion::getInfoPagination();

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

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

        (new PaginatorGestion())->generate(10, 'CODE_ART');
        $stockArticles = (new Listes($this->pdo))->listStockArticles($post);
        $infoPagination = PaginatorGestion::getInfoPagination();

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

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

        (new PaginatorGestion())->generate(10, 'CODE_ART');
        $articles = (new Listes($this->pdo))->listeArticlesNotInSarticles($post);
        $infoPagination = PaginatorGestion::getInfoPagination();

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

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

        (new PaginatorGestion())->generate(10, 'CODE');
        $magasiniers = (new Listes($this->pdo))->listMagasiniers($post);
        $infoPagination = PaginatorGestion::getInfoPagination();

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

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

        (new PaginatorGestion())->generate(8, 'IDRAYON');
        $listeRayon = (new Listes($this->pdo))->listeRayon($post);
        $infoPagination = PaginatorGestion::getInfoPagination();

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

    public function typeCarSelAction():string
    {
        $post = $this->request->getParsedBody();
        (new PaginatorGestion())->generate(8, 'ORDRE_CAR', 'asc');
        $liste = (new Listes($this->pdo))->listeTypeCarSelAction($post);
        $infoPagination = PaginatorGestion::getInfoPagination();

        foreach ($liste as &$carac) {
            $carac['ICONE_CAR'] = str_replace('%_images%', (new ParseBase1())->getPath()->images, $carac['ICONE_CAR']);
        }

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

    public function articlesCatalogueAction():string
    {
        $post = $this->request->getParsedBody();
        (new PaginatorGestion())->generate(8, 'IDLIGNE', 'asc');
        $liste = (new Listes($this->pdo))->listeArticleCatalogue($post);

        foreach ($liste as &$v) {
            if ($post['byId']) {
                $v['ID'] = $v['IDLIGNE'];
            } else {
                $v['ID'] = implode('|', [
                    $v['ID_CATAL'],
                    $v['CODEARTI'],
                    $v['CODEFOUR'],
                    $v['REFARTFOU'],
                    $v['FABRICANT'],
                    $v['REFARTFAB']
                ]);
            }
        }

        $infoPagination = PaginatorGestion::getInfoPagination();

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